Commit Graph

36 Commits

Author SHA1 Message Date
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
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
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
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
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
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 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
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
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
Evgeny Rozaliev e0a598fb34 TinyVec::from([T]) (#66) 2020-03-17 14:15:39 -06:00
Wesley Norris 0dababa9fe Add TinyVec::from(slice) test 2020-01-24 08:24:44 -05:00
Lokathor 641590223e cargo fmt hasn't been used in a while it seems. 2020-01-19 13:02:54 -07:00
mental 73a5050f0d Account for heap capacity in capacity unit test 2020-01-19 05:07:35 +00:00
mental f5de23493b Account for heap allocated capacities. 2020-01-19 04:57:34 +00:00
Andreas Molzer fd3c92c351 Test and fix removal at past-the-end index 2020-01-18 13:24:58 +01:00
Lokathor 822b590f4c more docs, more renames, closer to being good. 2020-01-13 21:34:22 -07:00
Lokathor 85377b6815 rename arrayish to array I guess
The "ish" part was always supposed to be temporary.
2020-01-13 21:12:04 -07:00
Lokathor d3b27fa49c docs and rename the feature to alloc
Closes https://github.com/Lokathor/tinyvec/issues/18
We could discuss the "goals" section more of course, but for now it's enough to call that issue closed.
2020-01-13 19:55:38 -07:00
Lokathor 93ff65b237 Merge pull request #16 from Nemo157/fix-resize
Fix TinyVec::resize across inline/heap boundary
2020-01-13 18:49:19 -07:00
Wim Looman 3335c63092 Fix TinyVec::resize across inline/heap boundary 2020-01-13 20:21:46 +01:00
Wim Looman 71ad62a90f Fix ArrayishVec::swap_remove for last element 2020-01-13 19:42:49 +01:00
Wim Looman 95c991d6b4 Fix TinyVec::drain implementation 2020-01-12 14:07:19 +01:00
Wim Looman 9117614aa9 Fix ArrayishVec::drain implementation
The end bound was off by one
2020-01-12 13:54:35 +01:00
Lokathor 8be0c601a3 we're calling the ArrayishVec done for now I think 2020-01-09 22:17:14 -07:00
Lokathor 7d4f8c20c3 append 2020-01-09 00:39:34 -07:00
Lokathor 1c81be96d3 Partial work on ArrayishVec 2020-01-07 23:10:38 -07:00
Lokathor bdf612651b Try to adopt 1.24 as the CI version
This would allow our crate to be used as a dependency of the `unicode-segmentation` crate.
2020-01-06 20:28:09 -07:00
Lokathor d343ee8c14 add truncate method and tests based on the Vec examples 2020-01-06 20:05:08 -07:00
Lokathor 0b2bdd58dc base files 2020-01-06 19:29:40 -07:00