530 Commits

Author SHA1 Message Date
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 345d420b65 Merge pull request #116 from bluss/maybe-uninit-for-0.5
Update ArrayString to use union and prepare for 0.5
2018-12-18 22:03:24 +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 f218e094d4 MAINT: Edit travis setup for changed crate features 2018-12-18 21:40:39 +01:00
bluss c4b95279e9 MAINT: Remove feature with no effect ("use_union") 2018-12-16 18:32:14 +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 7496a5f597 Merge pull request #115 from bluss/merge-0.4
Merge 0.4 branch to master
2018-12-16 18:28:50 +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 2316b85fbc 0.4.9 2018-12-16 18:02:49 +01:00
bluss 3edc9a6de7 Merge pull request #114 from bluss/maybe-uninit-0.4
Implement a "MaybeUninit" and use it conditionally (0.4.x version)
2018-12-16 17:51:59 +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 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 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 cc3cb8d282 MAINT: Test the 0.4 branch in travis 2018-12-15 14:35:53 +01:00
bluss ac94d167a2 MAINT: Test the 0.4 branch in travis 2018-12-15 14:35:25 +01:00
bluss bf3b8c4f0f FIX: Unused code warning in array trait 2018-11-30 18:49:28 +01:00
bluss 226de4c9ba TEST: Add test for try_extend_from_slice's error 2018-11-30 18:48:43 +01:00
bluss ef7ab569b1 Merge pull request #112 from bluss/extend-improvement
Improve .extend() performance (?)
2018-11-28 17:01:41 +01:00
bluss fd98c6647d FEAT: Improved extend performance 2018-11-28 16:04:05 +01:00
bluss 675182bcbd TEST: Tweak extend benchmarks, add write benchmark
.write() is explicitly memcpy, so it's nice to compare with.
2018-11-28 16:04:05 +01:00
bluss fa95a80bbc FIX: Rename the extend_from_slice bench 2018-11-28 16:01:23 +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
bluss d9222c0e61 Merge pull request #101 from Thomasdezeeuw/extend_from_slice
Add ArrayVec.extend_from_slice and capacity_left
2018-11-28 15:51:56 +01:00
Thomas de Zeeuw 8a8332f886 TEST: add benchmark for extend_from_slice 2018-11-26 13:06:06 +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 d84cb377a9 Merge pull request #111 from bluss/miri-complaints
Fix just a few stacked borrow issues, and improve extend performance
2018-11-25 17:17:43 +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
bluss 23128275ee TEST: Update benchmark for extend_from_slice
The benchmark was optimized out totally. We think of that as a good
sign, the new extend became transparent to the compiler and we had to
get smarter in how to fool it.
2018-11-25 16:34:47 +01:00
bluss 91e88a4976 FEAT: Simplify stack guard in extend
This simplification -- borrowing self.len instead of self, leads to
an improvement in the extend_from_slice benchmark.

It's also guided by the discussion of stacked borrows; the old code
would be invalid, because the whole self is borrowed while ptr is derived from
self.
2018-11-25 16:33:07 +01:00
bluss b1976641f3 MAINT: Test in travis from Rust 1.20 2018-11-25 10:44:23 +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 e80446c646 Merge pull request #102 from gnzlbg/ub
Fix undefined behavior in DerefMut of ArrayString
2018-11-25 10:34:54 +01:00
bluss 21034b357e Merge pull request #71 from clarcharr/master
Make zero-capacity ArrayVec a zero-sized type.
2018-11-25 10:34:12 +01:00
bluss 74f86a710e Merge branch 'master' into master 2018-11-25 10:29:22 +01:00
bluss c8d12cecb3 0.4.8 2018-11-25 09:46:33 +01:00
bluss f5adeab5f5 Merge pull request #109 from bluss/array-sizes-33-255
Add all array sizes 33-128 and 129-255 under a feature gate
2018-11-25 09:41:35 +01:00
bluss d77b93079f TEST: Add minimal tests for new array sizes 2018-11-25 09:36:22 +01:00
bluss e355c9eb31 DOC: Hide Array methods on impls
These just clutter up the docs. Most important that the users can see
the list of implemented array sizes, not the methods for each of those.
2018-11-25 09:32:29 +01:00
bluss 9d1ede62ea MAINT: Add Rust 1.22 to travis build 2018-11-25 09:26:01 +01:00
bluss 4dc503e17d MAINT: Add array sizes to travis build 2018-11-25 09:25:30 +01:00
bluss 50728e4cda DOC: Add doc for additional array features flags 2018-11-25 09:24:16 +01:00
bluss f1d73f4feb FEAT: Add array sizes 33 to 128 and 129 to 255 under feature flags
This way we cover all users up to 256 at least. The reason these are not
enabled by default is that they slow down the compilation of the crate
by a factor of 2-3x.
2018-11-25 09:22:51 +01:00
bluss 813e9dde42 MAINT: Update readme files for nodrop crates
Fixes #107
2018-11-12 22:26:20 +01:00