Commit Graph

227 Commits

Author SHA1 Message Date
bluss b24baf1b5d DOC: Tweak formatting and wording of unstable-const-fn feature 2021-03-28 22:47:22 +02:00
rodrimati1992 5ad4687b1b Made ArrayVec::new and ArrayString::new const fns
Added utils module with a `MaybeUninit` helper type to construct `[MaybeUninit<T>; N]`

Removed all uses of the "unstable-const-fn" feature, and documented it as being deprecated.

Changed `assert_capacity_limit` macro to work in const contexts.
2021-03-28 14:48:27 -03:00
Jacob Kiesel 0bc7ffc9fd Minor fix to macro definition 2021-03-26 12:34:16 -06:00
Josh Stone dc0360ffd2 DOC: Fix typo in ArrayVec::is_full 2021-03-24 16:57:10 -07:00
bluss fd724e0edb DOC: Minor tweaks to docs 2021-03-24 18:43:09 +01: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 f9f58c94b7 FIX: Use more efficient cloning in IntoIter::clone
Using .extend_from_slice() where possible.
2021-03-23 21:57:11 +01:00
bluss cf283a0ee6 FIX: Code cleanup in .into_inner()
Prefer ManuallyDrop instead of forget (more modern style preference -
with the benefit that the ManuallyDrop style sets up the non-dropping
before taking further actions).
2021-03-23 21:55:54 +01:00
bluss 74039f1b4c DOC: Doc comment and example updates for ArrayVec 2021-03-23 21:55:43 +01:00
bluss 666c5ece59 API: Remove deprecated ArrayVec::dispose 2021-03-23 21:43:19 +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 d273861cde DOC: Update MSRV doc to Rust 1.51 2021-03-23 18:22:12 +01:00
bluss c751c2204f Remove old Array and Index traits 2021-03-23 18:22:12 +01:00
bluss f2e9378fd6 FIX: Fix unstable-const-fn feature 2021-03-23 18:22:12 +01:00
bluss 6daae9ae68 FIX: Fix serde feature for const gen 2021-03-23 18:22:12 +01:00
bluss c9b095f263 FEAT: Port ArrayString to const generics 2021-03-23 18:22:12 +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
bluss 02ab4dc796 FEAT: Add new const generics version of ArrayVec (first draft) 2021-03-23 18:08:07 +01:00
bluss 630b81b848 Use ArrayVecImpl in ArrayVec 2021-03-23 17:51:10 +01:00
bluss a2b2efd379 Add ArrayvecImpl, base implementation of ArrayVec 2021-03-23 17:51:10 +01:00
bluss c3ef5fe840 MAINT: Move ArrayVec implementation to module 2020-12-17 22:58:27 +01:00
bluss 5ef684920d MAINT: Fix doc link in crate 2020-12-17 22:56:23 +01:00
Caio 6dccb480f7 Impl TryFrom<fmt::Arguments<'a>> for ArrayString
Shortcut for

```
use fmt::Write;
let mut v = Self::new();
v.write_fmt(f).map_err(|e| CapacityError::new(e))?;
```
2020-12-09 20:21:03 -03:00
bluss 0acbba4ceb Merge pull request #165 from c410-f3r/try
impl TryFrom<&'a str> for ArrayString
2020-12-01 02:22:36 +01:00
bluss 50c9ed1abd Merge pull request #166 from hbina/use_add_instead_of_offset
Use `add` instead of `offset` so we don't need to cast to isize.
2020-10-23 18:13:41 +02:00
Hanif Bin Ariffin 92867bb118 Use add instead of offset to avoid casting to isize. 2020-10-21 20:50:00 +08:00
Caio 2267276dbb impl TryFrom<&'a str> for ArrayString 2020-08-28 08:16:20 -03:00
Mara Bos fe70c23e94 Add unstable-const-fn feature to make new() functions const. 2020-06-30 20:56:00 +02:00
Paul Kernfeld 675e992741 allow items that implement Clone 2020-05-12 14:57:38 -04:00
Paul Kernfeld 488efd0b3e impl<A: Array> TryFrom<&[A::Item]> for ArrayVec<A>
For issue #106
2020-05-12 12:04:09 -04:00
bluss 902114f62f Merge pull request #157 from AnderEnder/remove-deprecated-error-description
Remove deprecated Error::description
2020-03-15 21:27:36 +01:00
Andrii Radyk 2755d4acb3 remove deprecated Error::description 2020-01-04 00:50:35 +01:00
Ralf Jung b7fd8d6a22 enable another unwinding test in Miri 2019-12-07 12:13:31 +01:00
bluss badc118d6a Merge pull request #143 from nicbn/is_empty
Add is_empty method for ArrayVec and ArrayString
2019-11-20 18:59:17 +01:00
bluss 481c8ab683 Merge pull request #144 from RalfJung/miri
fix drain_range in Miri and add Miri to CI
2019-11-20 18:57:16 +01:00
Phlosioneer 33d5d2ed96 Fix outdated comment
Comment referenced NoDrop which is no longer used.
2019-11-20 02:03:05 -05:00
Ralf Jung 9ed6941a51 run miri on CI 2019-11-16 09:52:18 +01:00
Ralf Jung 9beb753473 fix aliasing in drain_range 2019-11-16 09:52:18 +01:00
nicbn 633c863b0a Add is_empty method for ArrayVec and ArrayString 2019-11-14 18:58:22 -03:00
bluss 090a5c50cb FIX: Support uninitalized data in encode_utf8, and update try_push
We were using &mut [u8] in encode_utf8, but this is not right according
to the developing unsafe coding guidelines. We need to use raw pointers
to write to possibly uninit memory.

We use a raw pointer form for encode_utf8. It was first attempted to
encapsulate the trusted-to-be-valid raw pointer in a simple { *mut u8,
usize } struct, but the current way of passing ptr and len separately
was the only way to not regress performance.

This impl maintains the same performance in arraystring benches.

Add exhaustive-style tests for encode_utf8
2019-10-09 12:23:44 +02:00
bluss f665142854 FEAT: Add ArrayString::len
This method is no new feature, but it saves us from going through deref
to str to fetch the length.
2019-10-09 12:21:25 +02:00
bluss fd72321191 FIX: Replace uses of <[T]>::get_unchecked_mut with raw pointer accessor
This is a soundness fix w.r.t unsafe coding guidelines.

In some of the instances, `get_unchecked_mut() -> &mut T as *mut T` was
used in places where the element was potentially uninitialized.

This was a problem in push. (Not a problem in IntoIter next/next_back,
where the whole range we're iterating is initialized).
2019-10-09 10:09:07 +02:00
bluss 1483c6d372 FIX: Adjust (mostly remove) inline directives
Using the following principles:

- Trivial methods (empty and simple constants) can be inline(always)
- Generic methods don't need any inlining directive at all.
  ..with the exception of Deref which just seems to be extra important.
- Non-generic items use #[inline] to enable inlining at the
  compiler's discretion.
2019-10-09 10:02:20 +02:00
bluss bf64376f91 API: Deprecate .dispose(), it no longer has a purpose without nodrop 2019-10-09 09:39:49 +02:00
Tobias Bucher 516f1511f6 Add as_{,mut_}ptr functions to ArrayVec, mirroring Vec
Fixes #135.
2019-10-05 21:01:58 +02:00
bluss 70a9ad67af DOC: Copyedit the Array doc comment again 2019-09-25 14:48:16 +02:00
bluss babae41d21 DOC: Add safety documentation on Array trait 2019-09-25 14:43:21 +02:00
bluss cac792e633 API: Rename feature flag serde-1 to serde
(Old concerns don't matter anymore, especially with renamed deps.)
2019-09-25 14:34:08 +02:00
bluss aece292b6c API: Use RangeBounds for .drain()'s range argument 2019-09-17 21:33:32 +02:00
bluss 062247818a FIX: Remove unused cfg variable 2019-09-02 22:08:00 +02:00