Commit Graph

194 Commits

Author SHA1 Message Date
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
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 470cfd2a48 FIX: Update serde impls for Array changes 2019-09-01 14:48:14 +02:00
bluss 7c33afb3ae DOC: Update min rust version to Rust 1.36 for MaybeUninit 2019-09-01 14:48:14 +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 f2aad9f9a7 API: Update ArrayExt's methods to expose slices instead of pointers
This is a nicer and simpler interface to expose, since the ref to uninit
array to pointer cast is not usable anyway (it's historic now, arrayvec
itself does not use it anymore).
2019-09-01 14:47:44 +02:00
bluss 2a3397995d FIX: Fix .extend() for ArrayVec with zero-sized type elements
The raw pointer walk did not do the right thing for ZST, because when
offsets are zero, the start and end pointer would be the same and the
loop ends before incrementing the length correctly.
2019-09-01 14:07:58 +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 b56c3b78d0 FEAT: Use stable MaybeUninit when we can (feature detected) 2019-07-10 16:40:50 +02:00
Tobias Bucher 76e89544a5 Merge pull request #124 from seanchen1991/master
Add semicolon to return statement for consistency
2019-06-21 02:24:36 +02:00
Sean Chen aab420b2ec Add semicolon to return statement for consistency 2019-06-20 14:36:13 -07:00
Jan-Erik Rediger 841ca1492b Fix word duplication in docs 2019-04-22 14:29:08 +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 cffdb4602a Merge branch '0.4' of https://github.com/bluss/arrayvec
* '0.4' of https://github.com/bluss/arrayvec:
  0.4.10
  FIX: Remove unused Copy/Clone for MaybeUninit
  FIX: Use repr(C) MaybeUninit after discussion with RalfJung
2018-12-22 20:05:42 +01:00
bluss 06930d27ce FIX: Remove unused Copy/Clone for MaybeUninit 2018-12-22 19:59:32 +01:00
bluss 9fc6737e1b FIX: Use repr(C) MaybeUninitCopy after discussion with RalfJung
We have a recommendation from the unsafe-wg (no rule yet), that
repr(C) for unions should work this way, so that we can cast from the
union type to one of its fields.
2018-12-22 14:28:20 +01:00
bluss 85d9a06a62 FIX: Use repr(C) MaybeUninit after discussion with RalfJung
We have a recommendation from the unsafe-wg (no rule yet), that
repr(C) for unions should work this way, so that we can cast from the
union type to one of its fields.
2018-12-22 14:25:16 +01:00
bluss 74745a9756 DOC: Update minimum rust requirement to Rust 1.24
Rust 1.24 is on debian stable. It is compatible with crossbeam (Rust 1.26),
the rdep with most downloads.
2018-12-18 21:40:39 +01:00
bluss c4cd63209f FEAT: Use a separate union MaybeUninitCopy for ArrayString
This is the "real" union solution, and ArrayString can use it since its
backing array is Copy. Unfortunately, we'll have to use the Copy bound
on the type, making it "viral" and visible in the user API.
2018-12-16 18:32:14 +01:00
bluss 784ccc97ca DOC: Remove warning on ArrayVec's into_inner method 2018-12-16 18:32:14 +01:00
bluss f5290c1eea FIX: Remove unused .as_mut_ptr() on the Array trait
Raw pointer taking should go through the MaybeUninit wrappers around the
arrays anyway, when it is partially uninitialized, which it often is.

The remaining .as_ptr() and .as_slice() methods on Array is only used
on a fully initialized array in ArrayString::from_byte_string
2018-12-16 18:32:14 +01:00
bluss 6c099e148f FIX: Add associated constant for Array's capacity
This isn't of much use at the moment, but future Rust features could
mean we can use it.
2018-12-16 18:32:14 +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 d395a01e7c FIX: Remove use of uninitialized in ArrayString
We can't fix this properly (MaybeUninit with a union) until we change
the user visible API (we need to require that A: Copy.

As a temporary solution for arrayvec version 0.4.*, we use zeroed to
initialize an array of bytes, instead of using uninitialized. This may
have a negative performance impact, but the fix is to upgrade to future
arrayvec 0.5.
2018-12-15 15:12:03 +01:00
bluss 29012231a8 FEAT: Implement a "MaybeUninit" and use it conditionally
Use a build script to detect if we can use MaybeUninit or NoDrop.
Enabling unstable features automatically is not ideal, but since it's
a soundness issue we should do it.

Use a MaybeUninit-like union on nightly when we can. We use a feature
detection script in build.rs, so that we also go back to the fallback if
the unstable feature changes in an unexpected way.

We need to continue to use NoDrop for best working stable
implementation, but we eagerly use our union solution where we can,
currently only in nightlies.

Rustc feature probe code written by Josh Stone (cuviper),
taken from num-bigint.
2018-12-15 15:12:03 +01:00
bluss bf3b8c4f0f FIX: Unused code warning in array trait 2018-11-30 18:49:28 +01:00
bluss fd98c6647d FEAT: Improved extend performance 2018-11-28 16:04:05 +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 c4b6e86211 REFAC: use extend_from_slice in Write implementation for ArrayVec 2018-11-26 12:59:30 +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 f40e708f7c FIX: In truncate, don't access self while holding raw pointer derived from self
Again, stacked borrows model makes the `self.set_len()` call illegal
because we are holding (and are going to use) another raw pointer
derived from self, `tail`.
2018-11-25 16:37:29 +01:00