Commit Graph

51 Commits

Author SHA1 Message Date
Lokathor feecd9ae83 make docs even more plain and simple. 2020-10-13 12:17:16 -06:00
Johnny c570a1148c Add into_inner method (#124)
* Add into_inner method

* Whoops, forgot the function
2020-10-13 12:07:20 -06:00
SlightlyOutOfPhase 0529972454 Implement [value; N] syntax support for array_vec! (#118)
* Implement `[value; N]` syntax for `array_vec!`

Also implement the `($array_type:ty)` form by just calling `default()` immediately, which makes more sense.

* Add tests for `[value; N]` macro form

* Implement `[value; N]` syntax for `tiny_vec!`

Also make the same improvement to the `($array_type:ty)` macro variant that I did for `array_vec!`.

* Add tests for `[value; N]` macro form
2020-10-11 18:42:51 -06:00
Nemo157 ea8efbc870 Fix building docs on docs.rs (#114)
* Don't enable nightly features when documenting on docs.rs

* Mark serde impls with doc(cfg)
2020-08-21 15:25:39 -06:00
Nemo157 d3c1c6a56d Replace A: Default bounds by a constructor on Array (#112)
* Add Array::default function to construct a default array

* Use Array::default instead of Default::default to allow supporting all array sizes

* Missed impl Array for [T; 33] 🍀

* Avoid needing `[T; N]: Default with const-generics
2020-08-17 10:55:51 -06:00
aspen 686f424212 Add Serde support (#110)
* Add Serde support.

* Removes `serde/alloc` from deps( tests still pass without it anyways)

* Fix some issues that could result in a panic.

* Wait, actually use the size_hint properly.

* Error instead of silent truncation.

* That wasn't meant to be a default feature.
2020-08-17 07:39:29 -06:00
Soveu ed749ef260 SliceVec fuzzer + overflow fix on usize::MAX ranges (#99)
* add slicevec fuzzer

* prevent overflow on range calculation
2020-08-09 10:45:19 -06:00
Lokathor 5b052e0139 apply some fn attributes. 2020-08-08 19:01:45 -06:00
Soveu 4f976c9b45 Fuzz Fuzz Fuzz (#98)
* more features for fuzzing

* arrayveciter fuzzer + overflow fix

* moar fuzzers and tinyvecdrain change

* cargo fmt

* Self on enums is not stable in 1.36

* 🐞 BUGFIX: ArrayVecIterator::nth_back

* cargo fmt
2020-08-02 14:40:13 -06:00
Soveu f2ec57851f Change len type from usize to u16 (#97)
* change len from usize to u16

* cargo fmt

* change len to tail
2020-07-31 13:46:05 -06:00
Soveu 102439ef9d A bit of everything for iterators (#87)
* slight changes functions that use drain

* bug in arrayvec iter

* reverse iter for arrayvec

* nth_back is stable since 1.37

* simpler drain for arrayvec

* soveu forgot to add changed files

* fmt + feature for rustc >= 1.40

* cosmetic changes

* does the ci work now?

* SHNAAAAAAAAATSEEEEEEEEL
2020-07-23 13:28:01 -06:00
Benjamin Scherer 689cc12a11 Add ArrayVec::splice and TinyVec::splice (#85)
* Add ArrayVec::splice and TinyVec::splice

Added for closer API parity with std::Vec

* Fix ArrayVec::splice example typo

* Removed FusedIterator bound from splice

This bound could've caused confusing error messages, and was
inconsistent with the Vec API. splice now uses fuse itself to ensure
consistency. Vec::splice consumes the whole iterator at once, so it
essentially has the same behavior, but this implementation gradually
consumes the iterator as elements are drained, so this fuse is necessary
to keep the behavior the same.

* Reserve additional capacity in TinyVecSplice

Used TinyVec::reserve to pre-allocate space for elements being spliced
into the TinyVec after the splicing iterator is dropped. Used the lower
bound like Vec's splice does.

* Run rustfmt
2020-07-18 00:22:59 -06:00
Soveu 3919d5e804 "try_*" functions and "to_vec" for arrayvec (#82)
* change behavior on extend_from_slice, append

* preallocation in extend()

* append v2

* obviously

* fix resize_with

* try_functions and to_vec on arrayvec

* shrink_to_fit

* bit of cleaning

* cosmetic changes

* use asserts instead of if-panics

* I promise, this is the last commit

* examples, tests

* matches macro exists since rust 1.42

* Update tinyvec.rs

* new extend and insert

* mem::take is from rust 1.40
2020-07-17 16:07:10 -06:00
Benjamin Scherer d7588089c8 Make capacity() methods not rely on Array::CAPACITY (#83)
* Make capacity() methods not rely on Array::CAPACITY

Because Array isn't an unsafe trait, unsafe code cannot depend on the
length of a slice produced by Array::as_slice to be at least as long as
Array::CAPACITY. This means that unsafe code also cannot depend on
capacity() methods that return Array::CAPACITY. Returning the result of
a slice len() call ensures that if nothing else, with a sound
implementation of Array, capacity() methods will return a valid length
for a sub-slice of the backing array.

* Add comments explaining choice against using Array::CAPACITY
2020-07-15 21:02:26 -06:00
Lokathor b8771760cc Closes https://github.com/Lokathor/tinyvec/issues/75 (#77)
* Closes https://github.com/Lokathor/tinyvec/issues/75

* This is a breaking change to the macro

* benchmarks fixes.

* slim down to just `take`
2020-07-03 10:56:45 -06:00
Lokathor 3beff97fa6 Add the SliceVec type (#68)
* start of slicevec

* remove todo! because it's not in 1.36

* Update Cargo.toml

* slice vec into iterator

* slicevec drain

* complete last unimplemented

* remove the extra default feature

* spelling

* Update src/slicevec.rs

Co-Authored-By: Joshua Nelson <joshua@yottadb.com>

* docs clarification.

Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2020-04-22 12:31:56 -06:00
Josh Stone ef900b1ce6 impl IntoIterator for &/&mut ArrayVec (#69)
These just create slice iterators, but the impls are useful to have for
contexts that don't auto-deref, as in the new tests.
2020-03-31 13:36:39 -06:00
Lokathor 927fad5a21 Update arrayvec.rs 2020-02-11 12:32:18 -07:00
Lokathor d778fec9fb Update arrayvec.rs 2020-02-11 12:15:19 -07:00
Lokathor 0bd7f43809 Improve Write impl efficiency 2020-02-10 20:14:20 -07:00
Lokathor b80cbbc07b put in a highly experimental Write impl for ArrayVec of bytes 2020-02-10 20:02:56 -07:00
Lokathor 6ab291baab Closes https://github.com/Lokathor/tinyvec/issues/48 2020-02-10 19:52:15 -07:00
Wim Looman 0c915a5711 Allow inferring array type for macro constructors 2020-01-28 12:51:35 +01:00
Wim Looman 5bbed8e98c Make macros work without any other imports 2020-01-28 12:46:39 +01:00
mgostIH f829193f4e Fixed links in documentation by removing ::<A> 2020-01-26 22:25:33 +01:00
Lokathor 05eb8bf101 clippy 2020-01-26 13:47:24 -07:00
Lokathor 4d820bf22b Merge branch 'master' into small-updates 2020-01-26 13:37:57 -07:00
Lokathor 10e37daeb7 Merge pull request #56 from mgostIH/drain
Added more efficient implementation for ArrayVecDrain
2020-01-26 12:39:16 -07:00
mgostIH da82aa007a Added more efficient implementation for ArrayVecDrain, changed a few internal members of the struct, tests passed 2020-01-26 13:51:25 +01:00
Wim Looman 44455944d4 impl Debug for {Tiny,Array}VecIterator 2020-01-24 14:40:17 +01:00
Lokathor d6d1c9db07 Convert code notes into GitHub issues 2020-01-24 02:46:18 -07:00
Lokathor ca709b0864 cleanups 2020-01-24 02:38:18 -07:00
Lokathor 4907f0267f add Hash to ArrayVec and TinyVec 2020-01-20 18:48:18 -07:00
Lokathor 30516bc4d6 greatly improve extend_from_slice (+formatting)
Closes https://github.com/Lokathor/tinyvec/issues/25
(Thanks ThatsNoMoon!)
2020-01-19 13:02:14 -07:00
Lokathor b008c95a37 improve ArrayVec::push panic message
Closes https://github.com/Lokathor/tinyvec/issues/24
2020-01-19 12:59:21 -07:00
Lokathor b19f3928f9 Merge pull request #36 from HeroicKatora/fill
Add a fill method, a panic-free extend alternative
2020-01-18 19:14:17 -07:00
Lokathor e87dfb7b25 Merge pull request #34 from HeroicKatora/retain
Implement linear time retain
2020-01-18 19:00:53 -07:00
Andreas Molzer 83664ad87e Add a fill method, a panic-free extend alternative
This is an alternative to `Extend::extend` method for cases where the
length of the iterator can not be checked. Since this vector can not
reallocate to increase its capacity, it is unclear what to do with
remaining elements in the iterator and the iterator itself. The
interface also provides no way to communicate this to the caller.
2020-01-18 19:28:36 +01:00
Andreas Molzer 4cbd1db0a0 Fix element drop order on failed insert 2020-01-18 19:02:22 +01:00
Andreas Molzer b23ac5d886 Implement linear time retain 2020-01-18 18:37:38 +01:00
Andreas Molzer 04c799ffcf Simplify resize with element or function
Avoids a call to Clone of the element by using the provided instance as
the one inserted last. A similar optimization is used in the standard
library. Also changes the iteration to an independent iterator as the
number of insert elements must be known in advance.
2020-01-18 18:27:03 +01:00
Andreas Molzer a8c5b4e7ac Use mem::take shorthand for defaulted replace
This makes the code more readable by shortening lines and avoid explicit
or redundant type annotations. The core function would require a rust
version of 1.40 so straightforward implementation is added to the crate.
2020-01-18 18:26:10 +01:00
Andreas Molzer 2f94e40d81 Switch to slice swapping for split
The new slice is already initialized with default values for T due to
the constructor used. Instead of using different defaulted values for
replacing the split-off instances we can simply swap slices. This
reduces pressure on the optimizer and uses a probably optimized method
from the core library.
2020-01-18 17:24:27 +01:00
Andreas Molzer fd3c92c351 Test and fix removal at past-the-end index 2020-01-18 13:24:58 +01:00
Lokathor 66c99e290b We'll call this a 1.0 canidate! 2020-01-18 00:16:25 -07:00
Lokathor 2d484cbebe remove the try_push thing 2020-01-17 23:28:25 -07:00
Lokathor 6afb9103ea breaking: make Array trait follow standard Rust naming 2020-01-17 22:47:53 -07:00
Lokathor a59fe3ebc9 Update arrayvec.rs 2020-01-15 19:45:49 -07:00
Lokathor 5e5c0385cc doc them nightly methods. 2020-01-13 21:38:15 -07:00
Lokathor 822b590f4c more docs, more renames, closer to being good. 2020-01-13 21:34:22 -07:00