Commit Graph

137 Commits

Author SHA1 Message Date
ajtribick a53c254b88 Error implementation for TryFromSliceError (#160)
* Fix spelling of 'length'

* Add Error implementation to TryFromSliceError
2022-04-23 12:18:14 -06:00
i509VCB 7c85b93627 add try_ functions for fallible heap growth (#158)
* add try_ functions for fallible heap growth

* tests for try_ functions
2022-04-20 12:43:34 -06:00
Mads Marquart 596636ad47 Fix building on Rust 1.34 with alloc feature enabled (#154)
* CI: Build Rust 1.34 with features

* Fix building on Rust 1.34 with alloc feature enabled

* CI: Fix building with features
2021-11-09 12:25:23 -07:00
Lokathor c29345bdcc add the doc attribute. 2021-09-24 18:51:21 -06:00
Eric Ridge 750f684d4f Issue #151: impl std::io::Write for u8-based TinyVecs (#152)
* impl std::io::Write for u8-based TinyVec

* undo bad formatting

* fix formatting
2021-09-24 11:58:46 -06:00
Ben Kimock b645e08d8b Rename nightly_const_generics to rustc_1_55 and remove feature gate (#149) 2021-09-11 18:54:59 -06:00
Lokathor 13008731ba improve clone impl as per https://github.com/Lokathor/tinyvec/issues/143 (#144)
* improve clone impl as per https://github.com/Lokathor/tinyvec/issues/143

* per https://github.com/Lokathor/tinyvec/pull/144#discussion_r669769122

* rustfmt.

* formatting

* whoops haha that's a little tricky to get the types to line up

we don't have deref for the A so we have to keep using as_slice_mut and such
2021-07-21 18:11:46 -06:00
Andrew Jeffery afb1dc4df8 Add arbitrary implementations for TinyVec and ArrayVec (#146) 2021-07-13 06:52:19 -06:00
Ole Bertram 3c5ce49e36 Implement DoubleEndedIterator for TinyVecIterator (#145) 2021-07-13 06:49:17 -06:00
Cryptjar 25654733a1 Add a from_array_empty constructor which is a const fn. (#141)
Also lifts the `A: Array` constraint on ArrayVec as it was not used yet
and would otherwise conflict with the const fn, which currently (Rust 1.51)
may not have any trait constraints.

Since this commit only adds a new function and lifts a constraint, this
should be perfectly backwards compatible.
2021-04-04 09:13:15 -06:00
Lokathor 0e0dc46d37 use alternate printing when requested. (#139) 2021-04-01 19:47:38 -06:00
Soveu 35082e1d15 TinyVec::fmt - fix pretty printing (#138)
* TinyVec::fmt - fix pretty printing

* ArrayVec::fmt - fix pretty printing
2021-03-24 11:55:02 -06:00
Michael Morgan 8d8ae29ba5 Add TryFrom<&'_ [A::Item]> for ArrayVec<A> (#134) 2021-03-01 20:02:24 -07:00
Ben Kimock 9dca7ce1a3 swap instead of rotate_right, explain in comment (#129) 2021-01-18 16:03:40 -07:00
Ben Kimock db5465a108 optimize From<&[T]> (#132) 2021-01-18 15:19:28 -07:00
Ben Kimock 1624ff22e3 optimize ArrayVec::fill (#131) 2021-01-18 15:17:52 -07:00
Ben Kimock 2d45d6e7aa Swap each element instead of calling rotate_left (#128) 2021-01-13 19:40:55 -07:00
Ben Kimock 7bb8a78f94 Outline the drain to heap logic in TinyVec::push (#127)
* Outline the drain to heap logic in TinyVec::push

* Use #[cold] and explain the outlining in a comment
2021-01-13 17:51:07 -07:00
Lokathor 29a97b764a additional doc attributes. 2020-10-14 13:11:32 -06:00
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
Caio e1f3dc9c99 Use min_const_generics (#108) 2020-08-13 09:53:22 -06:00
Lokathor f84256f127 correct docs.rs error. 2020-08-09 12:15:50 -06:00
Soveu f17209f3c2 Make code DRYer (#107)
* make code dryer

* arrayset definition caused cargo fmt to fail
2020-08-09 10:52:06 -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 d3f66a20c5 Add doc attributes for docs.rs build (#105)
* add with_capacity method.

* Improve docs.

* .

* name the correct requirements.
2020-08-09 10:30:17 -06:00
Lokathor 1d2a3d164b alter docs. (#106) 2020-08-09 10:27:55 -06:00
Lokathor 4987d56d98 Cratesio fix (#104)
* add with_capacity method.

* Improve docs.
2020-08-09 09:13:26 -06:00
Lokathor 2fd9f55886 add with_capacity method. (#103) 2020-08-08 19:49:31 -06:00
Lokathor 533db28003 more fn attributes. 2020-08-08 19:09:18 -06:00
Lokathor b5c4a51427 Formally move the arrayset into a backup folder. It will become a separate crate some day. 2020-08-08 19:04:39 -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
Soveu 1bfc9c0479 Pre-allocate memory in extend_from_slice, extend and append functions (#80)
* change behavior on extend_from_slice, append

* preallocation in extend()

* append v2

* obviously

* fix resize_with
2020-07-17 10:21:06 -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 5c390e49a2 Relicense from Zlib to Zlib OR Apache-2.0 OR MIT (#81)
* rustfmt

* Replace crate description so Shnatsel doesn't need to sign off on the relicense.

* write more crate docs.
2020-07-15 06:45:39 -06:00
Lokathor ebf14aa539 fix my own error 2020-07-03 21:45:55 -06:00
Lokathor 26f4f28942 Update arrayset.rs 2020-07-03 21:34:57 -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
Benjamin Scherer 0fdcd0b4db Modify tiny_vec! to avoid error on non-Copy types (#74)
* Modify tiny_vec! to avoid error on non-Copy types

Using $elem in two closures in the previous version of the macro created
errors when using types that don't implement Copy. Moving the decision
of whether to allocate or use an inline array to the macro invocation
resolves this error as the borrow checker can see that both branches are
never taken together.

* Add test for tiny_vec! using non-Copy types

* Fix inference issue

* Use full crate path in tiny_vec!
2020-06-18 09:22:21 -06:00
Diggory Hardy a5552d22e5 Implement ArraySet (#73) 2020-06-18 09:21:53 -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