76 Commits

Author SHA1 Message Date
wub 77041876ee Add len_u16 and len_u8 features. 2026-05-24 10:31:01 -07:00
Sergey "Shnatsel" Davidoff 0ff49b9614 add a test demonstrating double-free in extend() for ZSTs 2026-05-03 14:23:52 +02:00
Kornel 812c83a2b1 Use 16-bit lengths on 16-bit targets 2024-10-17 10:55:15 +02:00
Ulrik Sverdrup cee33ee1e8 Remove disabled and now-redundant tests 2024-07-30 17:34:36 +02:00
Jan Špaček ae6cfd3baf Improve optional support for borsh serialization
- Do not allocate when deserializing ArrayString
- Serialize length as u32, not as u64, to be consistent with
  serialization of [T] and str
- Add tests
2024-03-07 21:11:18 +01:00
Caio e98cb1c81a Typo 2021-08-13 20:06:03 -03:00
Caio f5acafa0b3 Add zero_filled constructor 2021-08-13 20:04:44 -03:00
Conrad Ludgate 16c8e4d40d tests + docs 2021-05-29 13:01:14 +01:00
bluss b7f3aa9fce FIX: Add new_const() for const construction and revert new to old version
The new() function is significantly faster, it optimizes better at the
moment/in current rust. For this reason, provide a const fn constructor,
but not as the default `new`.
2021-03-29 21:52:39 +02:00
rodrimati1992 165414e0d9 Added tests for construction in const context
Updated the capacity panic test
2021-03-28 14:49:45 -03:00
bluss 0c90469b61 FEAT: Use u32 for the length field in arrayvec
Store the length as u32 internally. This is to shrink the size of the
ArrayVec value (when possible, depending on element type).

Inline storage vectors larger than u32::MAX are very unlikely to be
useful - for these cases, prefer using Vec instead.

It's not possible to have the CAP type parameter be of type u32 (missing
features in const evaluation/const generics). We also have to panic at
runtime instead of having a static assertion for capacity, for similar
reasons.
2021-03-24 18:43:09 +01:00
bluss a554ea219a API: Panic in .extend() and from_iter on capacity exceeded
This regresses performance of the .extend(s) benchmark where s is a
slice; to compensate add a private extend_from_slice method that we can
use where possible (clone_from, try_from).
2021-03-23 19:33:10 +01:00
bluss 6daae9ae68 FIX: Fix serde feature for const gen 2021-03-23 18:22:12 +01:00
bluss 18877f243a TEST: Fix size assertion test for const gen
With const generics we can't avoid the usize (or other type) length
field.
2021-03-23 18:08:13 +01:00
bluss 5502324b6f TEST: Fix arrayvec tests for const gen
Just search/replace for syntax [T; N] -> T, N and it works.
2021-03-23 18:08:07 +01:00
Caio cca663f806 Add test 2020-12-10 13:54:10 -03:00
Paul Kernfeld 675e992741 allow items that implement Clone 2020-05-12 14:57:38 -04:00
Ralf Jung b7fd8d6a22 enable another unwinding test in Miri 2019-12-07 12:13:31 +01:00
Ralf Jung 9ed6941a51 run miri on CI 2019-11-16 09:52:18 +01:00
bluss abf1bb5a0a TEST: Update .travis for serde-1 to serde rename 2019-09-25 14:46:32 +02:00
bluss ba4d98c5c7 TEST: Update tests for passing without std feature 2019-09-25 14:37:06 +02:00
bluss aece292b6c API: Use RangeBounds for .drain()'s range argument 2019-09-17 21:33:32 +02:00
bluss e86a32d454 MAINT: Port to Rust 2018 edition 2019-09-02 22:07:30 +02:00
bluss f952e2c788 MAINT: Use ? operator instead of try!() macro 2019-09-02 22:06:20 +02:00
bluss 8093e8d886 FEAT: Switch to using MaybeUninit for everything
Use std::mem::MaybeUninit and stop using nodrop as a fallback.
This means we require Rust 1.36
2019-09-01 14:48:14 +02:00
bluss f7381fa699 TEST: Add test for extending array of ZST
This demonstrates a bug in current extend.
2019-09-01 13:41:30 +02:00
bluss e68c0c7b48 Merge branch '0.4' into master
* 0.4:
  0.4.11
  TEST: Update tests for new MaybeUninit usage
  FEAT: Use stable MaybeUninit when we can (feature detected)
2019-07-10 17:51:59 +02:00
bluss 93220e55ae TEST: Update tests for new MaybeUninit usage
(Also remove the size check since we can't rely on it, even if we want
to ensure it has no overhead for the bytes case.)
2019-07-10 16:58:11 +02:00
Aleksei Voronov 9207e7442f Implement FromStr for ArrayString
This is very useful for generic code that may want to parse arbitrary
input string into arbitrary other types.

Limitations of the FromStr trait don't allow us to keep the original string slice
inside the CapacityError, unfortunately.
2018-12-23 12:50:29 +01:00
bluss 94ab27a649 Merge branch '0.4' of https://github.com/bluss/arrayvec into merge-0.4
* '0.4' of https://github.com/bluss/arrayvec:
  0.4.9
  TEST: Add test that ensures the MaybeUninit impl is used on nightly
  FIX: Remove use of uninitialized in ArrayString
  FEAT: Implement a "MaybeUninit" and use it conditionally
  TEST: Add test that Some(ArrayVec<[&_;_]>).is_some()
  MAINT: Test the 0.4 branch in travis
2018-12-16 18:09:20 +01:00
bluss f0ec3e1398 TEST: Add test that ensures the MaybeUninit impl is used on nightly 2018-12-16 10:46:38 +01:00
bluss 8f8617b967 TEST: Add test that Some(ArrayVec<[&_;_]>).is_some()
This seems like a trivial test, but since it can fail, it shows us that
we don't have a sound implementation yet.
2018-12-15 14:47:19 +01:00
bluss 226de4c9ba TEST: Add test for try_extend_from_slice's error 2018-11-30 18:48:43 +01:00
bluss 47827e4843 FIX: Remake extend_from_slice to try_extend_from_slice
Do nothing and return an error, if the slice doesn't fit in the
remaining capacity.
2018-11-28 15:59:11 +01:00
bluss 8e5ff2d0fb FIX: Rename ArrayVec .capacity_left() → .remaining_capacity() 2018-11-28 15:52:46 +01:00
Thomas de Zeeuw 2120e4bb75 FEAT: Add ArrayVec.extend_from_slice 2018-11-26 12:59:30 +01:00
Thomas de Zeeuw d11c853346 FEAT: Add ArrayVec.capacity_left 2018-11-26 12:59:30 +01:00
bluss 233df73ab2 Merge pull request #98 from bluss/use-drop-in-place
Use drop_in_place for truncate and clear (and drop)
2018-11-25 10:40:17 +01:00
bluss 74f86a710e Merge branch 'master' into master 2018-11-25 10:29:22 +01:00
bluss d77b93079f TEST: Add minimal tests for new array sizes 2018-11-25 09:36:22 +01:00
Clar Fon 2d3c2e3a0f Test IntoIter::clone 2018-10-28 18:45:11 -04:00
Clar Charr 55bedc922a Make zero-capacity ArrayVec a zero-sized type. 2018-10-14 17:25:45 -04:00
bluss ac61ce748b TEST: Fix drop tests for older Rust
In the test, test with Vec first to see how Rust implements panic
recovery while elements drop. If Vec drops all the elements, then we
test that arrayvec does too.
2018-03-25 23:49:42 +02:00
bluss 3f9cdc52cd TEST: Add test that we drop all elements even if one of them panics 2018-03-25 23:26:20 +02:00
Tobias Bucher 9d0f801763 Add Default implementation for ArrayString
Fixes #67.
2017-09-11 19:59:06 +02:00
bluss 2de36ba2ca Add 65536 to the Array impls 2017-08-06 18:44:48 +02:00
bluss 313ebe8335 FEAT: Rename .remove_opt() to .pop_at() 2017-08-05 18:22:06 +02:00
bluss cf76a83a7f BUG: Fix import of CapacityError in tests 2017-08-05 18:21:43 +02:00
bluss bc9e0362bd FEAT: Remove InsertError again
try_insert has a capacity error, but panics if the index is out of
bounds.
2017-08-05 17:40:12 +02:00
bluss 1e83039426 FEAT: Align ArrayString .push and .push_str with String
Use same signatures (meaning: panics on errors). Add fallible versions
.try_push() and .try_push_str()
2017-07-30 15:38:42 +02:00