Commit 9685f76a authored by Danny Willems's avatar Danny Willems
Browse files

Run `cargo vendor`

parent 872ca64d
{"files":{"Cargo.toml":"e7405a91fea075bb4fedb0e76e2039af27d6c380beaa31150f37655d79a7a3ab","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"0245ee104228a100ce5fceecf43e25faae450494d9173f43fd94c27d69fdac13","README.rst":"8fab86c3c759d153a1a8a48e5f7f48546c898f0ec91433001c57fe0002af6455","benches/arraystring.rs":"f12b890977117ebde4ca42bcd6b91f2a6a087f2b235aaca6d15e30d125ae9f67","benches/extend.rs":"c3d69cc488ec5341b019cfed545ebbfea252f98718037b413f6a349da9489d1b","custom.css":"e6f2cd299392337b4e2959c52f422e5b7be11920ea98d10db44d10ddef5ed47c","src/array.rs":"8a42b3ff7a5a0713e8ee22462f303b0ce15bdc49a9fd5eb64f58e56855bdf944","src/array_string.rs":"fdcc24f0fd07e781b378f5d0190279e6d9c89b422f67e546ae443c602f967896","src/char.rs":"40af597d93895f206abcd33953b5d3d5a512d3b16ff5f96e492e659d9cca4209","src/errors.rs":"dde99bffaddfd45396aab7e07642cc018ef5435fe60c4f26a2c05a36555be18c","src/lib.rs":"4c00e50b532aec68b52fde4a737b7b5980b0cfb28f5c09ab8408d04896895a87","src/maybe_uninit.rs":"00659a86e8f84852d4355077a16beceaad0440ac0e81851fbac712fdb1850622","tests/serde.rs":"18c165cf6024f04a25b19aa139657d7c59f72d1541c9b24b44f9eaea01f507db","tests/tests.rs":"9633b92fe6c650b9b816cecac23b9c9e6a0365b1f67d4f0bfaad9e645e2bdc49"},"package":"cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8"}
\ No newline at end of file
{"files":{"CHANGELOG.md":"c9e49774ee89a3b7b533362d82060a14f2777ccefbe03b956f6f08057b6c3600","Cargo.toml":"c736151a4747b2c041404d730e17dec631393c5feea287edc8a3e482f83a8927","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"0245ee104228a100ce5fceecf43e25faae450494d9173f43fd94c27d69fdac13","README.md":"f42eb73acbc7729825a836a532d1c8c6b71e006e0d87e549ea7a483da7472425","benches/arraystring.rs":"f12b890977117ebde4ca42bcd6b91f2a6a087f2b235aaca6d15e30d125ae9f67","benches/extend.rs":"c3d69cc488ec5341b019cfed545ebbfea252f98718037b413f6a349da9489d1b","ci/miri.sh":"59172afe080a3431f4e7dbd66d2040afa27ab9c0359532bd68f8f423261738de","custom.css":"e6f2cd299392337b4e2959c52f422e5b7be11920ea98d10db44d10ddef5ed47c","src/array.rs":"5fa75554ebdf595c918fe923a84678989fc420d800310ee19a21597f7d683b66","src/array_string.rs":"48c175371aed3372158a9331e939cffc2a11a09120253fa9d0521e5cbca7cfca","src/char.rs":"3fe9e9cc68fc7cedb238d53924b552b876a60c4fea85935d2f5d1ca0d41ffa3e","src/errors.rs":"ca44c0987f59ae57623088d80013e75129101caea93c278c8ebb0df898bc6b1b","src/lib.rs":"08270486d9e9d34e02e0edf227baf5e87b36d38d264da209d3b7f8962dce1b54","src/maybe_uninit.rs":"c81cf16f976bfaf7c1fe371aa2fba84872874fb0e43c96f63bef01cceb5e1d64","tests/serde.rs":"18c165cf6024f04a25b19aa139657d7c59f72d1541c9b24b44f9eaea01f507db","tests/tests.rs":"b9a3db8a0b957695d9ecc539a7ea2ded1eea3c6f76de8b5624c2b4eae95f1fdd"},"package":"23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"}
\ No newline at end of file
arrayvec
========
A vector with fixed capacity.
Please read the `API documentation here`__
__ https://docs.rs/arrayvec
|build_status|_ |crates|_ |crates2|_
.. |build_status| image:: https://travis-ci.org/bluss/arrayvec.svg
.. _build_status: https://travis-ci.org/bluss/arrayvec
.. |crates| image:: http://meritbadge.herokuapp.com/arrayvec
.. _crates: https://crates.io/crates/arrayvec
.. |crates2| image:: http://meritbadge.herokuapp.com/nodrop
.. _crates2: https://crates.io/crates/nodrop
Recent Changes (arrayvec)
-------------------------
- 0.5.2
- Add `is_empty` methods for ArrayVec and ArrayString by @nicbn
- Implement `TryFrom<Slice>` for ArrayVec by @paulkernfeld
- Add `unstable-const-fn` to make `new` methods const by @m-ou-se
- Run miri in CI and a few related fixes by @RalfJung
- Fix outdated comment by @Phlosioneer
- Move changelog to a separate file by @Luro02
- Remove deprecated `Error::description` by @AnderEnder
- Use pointer method `add` by @hbina
- 0.5.1
- Add ``as_ptr``, ``as_mut_ptr`` accessors directly on the ``ArrayVec`` by @tbu-
(matches the same addition to ``Vec`` which happened in Rust 1.37).
- Add method ``ArrayString::len`` (now available directly, not just through deref to str).
- Use raw pointers instead of ``&mut [u8]`` for encoding chars into ``ArrayString``
- Add `as_ptr`, `as_mut_ptr` accessors directly on the `ArrayVec` by @tbu-
(matches the same addition to `Vec` which happened in Rust 1.37).
- Add method `ArrayString::len` (now available directly, not just through deref to str).
- Use raw pointers instead of `&mut [u8]` for encoding chars into `ArrayString`
(uninit best practice fix).
- Use raw pointers instead of ``get_unchecked_mut`` where the target may be
uninitialized a everywhere relevant in the ArrayVec implementation
- Use raw pointers instead of `get_unchecked_mut` where the target may be
uninitialized everywhere relevant in the ArrayVec implementation
(uninit best practice fix).
- Changed inline hints on many methods, mainly removing inline hints
- ``ArrayVec::dispose`` is now deprecated (it has no purpose anymore)
- `ArrayVec::dispose` is now deprecated (it has no purpose anymore)
- 0.4.12
- Use raw pointers instead of ``get_unchecked_mut`` where the target may be
uninitialized a everywhere relevant in the ArrayVec implementation.
- Use raw pointers instead of `get_unchecked_mut` where the target may be
uninitialized everywhere relevant in the ArrayVec implementation.
- 0.5.0
- Use ``MaybeUninit`` (now unconditionally) in the implementation of
``ArrayVec``
- Use ``MaybeUninit`` (now unconditionally) in the implementation of
``ArrayString``
- The crate feature for serde serialization is now named ``serde``.
- Updated the ``Array`` trait interface, and it is now easier to use for
- Use `MaybeUninit` (now unconditionally) in the implementation of
`ArrayVec`
- Use `MaybeUninit` (now unconditionally) in the implementation of
`ArrayString`
- The crate feature for serde serialization is now named `serde`.
- Updated the `Array` trait interface, and it is now easier to use for
users outside the crate.
- Add ``FromStr`` impl for ``ArrayString`` by @despawnerer
- Add method ``try_extend_from_slice`` to ``ArrayVec``, which is always
- Add `FromStr` impl for `ArrayString` by @despawnerer
- Add method `try_extend_from_slice` to `ArrayVec`, which is always
effecient by @Thomasdezeeuw.
- Add method ``remaining_capacity`` by @Thomasdezeeuw
- Improve performance of the ``extend`` method.
- Add method `remaining_capacity` by @Thomasdezeeuw
- Improve performance of the `extend` method.
- The index type of zero capacity vectors is now itself zero size, by
@clarfon
- Use ``drop_in_place`` for truncate and clear methods. This affects drop order
- Use `drop_in_place` for truncate and clear methods. This affects drop order
and resume from panic during drop.
- Use Rust 2018 edition for the implementation
- Require Rust 1.36 or later, for the unconditional ``MaybeUninit``
- Require Rust 1.36 or later, for the unconditional `MaybeUninit`
improvements.
- 0.4.11
- In Rust 1.36 or later, use newly stable MaybeUninit. This extends the
- In Rust 1.36 or later, use newly stable `MaybeUninit`. This extends the
soundness work introduced in 0.4.9, we are finally able to use this in
stable. We use feature detection (build script) to enable this at build
time.
- 0.4.10
- Use ``repr(C)`` in the ``union`` version that was introduced in 0.4.9, to
- Use `repr(C)` in the `union` version that was introduced in 0.4.9, to
allay some soundness concerns.
- 0.4.9
- Use ``union`` in the implementation on when this is detected to be supported
- Use `union` in the implementation on when this is detected to be supported
(nightly only for now). This is a better solution for treating uninitialized
regions correctly, and we'll use it in stable Rust as soon as we are able.
When this is enabled, the ``ArrayVec`` has no space overhead in its memory
layout, although the size of the vec should not be relied upon. (See `#114`_)
- ``ArrayString`` updated to not use uninitialized memory, it instead zeros its
When this is enabled, the `ArrayVec` has no space overhead in its memory
layout, although the size of the vec should not be relied upon. (See [#114](https://github.com/bluss/arrayvec/pull/114))
- `ArrayString` updated to not use uninitialized memory, it instead zeros its
backing array. This will be refined in the next version, since we
need to make changes to the user visible API.
- The ``use_union`` feature now does nothing (like its documentation foretold).
- The `use_union` feature now does nothing (like its documentation foretold).
.. _`#114`: https://github.com/bluss/arrayvec/pull/114
- 0.4.8
- Implement Clone and Debug for ``IntoIter`` by @clarcharr
- Implement Clone and Debug for `IntoIter` by @clarcharr
- Add more array sizes under crate features. These cover all in the range
up to 128 and 129 to 255 respectively (we have a few of those by default):
- ``array-size-33-128``
- ``array-size-129-255``
- `array-size-33-128`
- `array-size-129-255`
- 0.4.7
- Fix future compat warning about raw pointer casts
- Use ``drop_in_place`` when dropping the arrayvec by-value iterator
- Use `drop_in_place` when dropping the arrayvec by-value iterator
- Decrease mininum Rust version (see docs) by @jeehoonkang
- 0.3.25
......@@ -120,107 +109,107 @@ Recent Changes (arrayvec)
- 0.4.5
- Add methods to ``ArrayString`` by @DenialAdams:
- Add methods to `ArrayString` by @DenialAdams:
- ``.pop() -> Option<char>``
- ``.truncate(new_len)``
- ``.remove(index) -> char``
- `.pop() -> Option<char>`
- `.truncate(new_len)`
- `.remove(index) -> char`
- Remove dependency on crate odds
- Document debug assertions in unsafe methods better
- 0.4.4
- Add method ``ArrayVec::truncate()`` by @niklasf
- Add method `ArrayVec::truncate()` by @niklasf
- 0.4.3
- Improve performance for ``ArrayVec::extend`` with a lower level
- Improve performance for `ArrayVec::extend` with a lower level
implementation (#74)
- Small cleanup in dependencies (use no std for crates where we don't need more)
- 0.4.2
- Add constructor method ``new`` to ``CapacityError``.
- Add constructor method `new` to `CapacityError`.
- 0.4.1
- Add ``Default`` impl to ``ArrayString`` by @tbu-
- Add `Default` impl to `ArrayString` by @tbu-
- 0.4.0
- Reformed signatures and error handling by @bluss and @tbu-:
- ``ArrayVec``'s ``push, insert, remove, swap_remove`` now match ``Vec``'s
- `ArrayVec`'s `push, insert, remove, swap_remove` now match `Vec`'s
corresponding signature and panic on capacity errors where applicable.
- Add fallible methods ``try_push, insert`` and checked methods
``pop_at, swap_pop``.
- Similar changes to ``ArrayString``'s push methods.
- Add fallible methods `try_push, insert` and checked methods
`pop_at, swap_pop`.
- Similar changes to `ArrayString`'s push methods.
- Use a local version of the ``RangeArgument`` trait
- Use a local version of the `RangeArgument` trait
- Add array sizes 50, 150, 200 by @daboross
- Support serde 1.0 by @daboross
- New method ``.push_unchecked()`` by @niklasf
- ``ArrayString`` implements ``PartialOrd, Ord`` by @tbu-
- New method `.push_unchecked()` by @niklasf
- `ArrayString` implements `PartialOrd, Ord` by @tbu-
- Require Rust 1.14
- crate feature ``use_generic_array`` was dropped.
- crate feature `use_generic_array` was dropped.
- 0.3.23
- Implement ``PartialOrd, Ord`` as well as ``PartialOrd<str>`` for
``ArrayString``.
- Implement `PartialOrd, Ord` as well as `PartialOrd<str>` for
`ArrayString`.
- 0.3.22
- Implement ``Array`` for the 65536 size
- Implement `Array` for the 65536 size
- 0.3.21
- Use ``encode_utf8`` from crate odds
- Add constructor ``ArrayString::from_byte_string``
- Use `encode_utf8` from crate odds
- Add constructor `ArrayString::from_byte_string`
- 0.3.20
- Simplify and speed up ``ArrayString``’s ``.push(char)``-
- Simplify and speed up `ArrayString`’s `.push(char)`-
- 0.3.19
- Add new crate feature ``use_generic_array`` which allows using their
``GenericArray`` just like a regular fixed size array for the storage
of an ``ArrayVec``.
- Add new crate feature `use_generic_array` which allows using their
`GenericArray` just like a regular fixed size array for the storage
of an `ArrayVec`.
- 0.3.18
- Fix bounds check in ``ArrayVec::insert``!
It would be buggy if ``self.len() < index < self.capacity()``. Take note of
- Fix bounds check in `ArrayVec::insert`!
It would be buggy if `self.len() < index < self.capacity()`. Take note of
the push out behavior specified in the docs.
- 0.3.17
- Added crate feature ``use_union`` which forwards to the nodrop crate feature
- Added methods ``.is_full()`` to ``ArrayVec`` and ``ArrayString``.
- Added crate feature `use_union` which forwards to the nodrop crate feature
- Added methods `.is_full()` to `ArrayVec` and `ArrayString`.
- 0.3.16
- Added method ``.retain()`` to ``ArrayVec``.
- Added methods ``.as_slice(), .as_mut_slice()`` to ``ArrayVec`` and ``.as_str()``
to ``ArrayString``.
- Added method `.retain()` to `ArrayVec`.
- Added methods `.as_slice(), .as_mut_slice()` to `ArrayVec` and `.as_str()`
to `ArrayString`.
- 0.3.15
- Add feature std, which you can opt out of to use ``no_std`` (requires Rust 1.6
- Add feature std, which you can opt out of to use `no_std` (requires Rust 1.6
to opt out).
- Implement ``Clone::clone_from`` for ArrayVec and ArrayString
- Implement `Clone::clone_from` for ArrayVec and ArrayString
- 0.3.14
- Add ``ArrayString::from(&str)``
- Add `ArrayString::from(&str)`
- 0.3.13
- Added ``DerefMut`` impl for ``ArrayString``.
- Added method ``.simplify()`` to drop the element for ``CapacityError``.
- Added method ``.dispose()`` to ``ArrayVec``
- Added `DerefMut` impl for `ArrayString`.
- Added method `.simplify()` to drop the element for `CapacityError`.
- Added method `.dispose()` to `ArrayVec`
- 0.3.12
......@@ -243,17 +232,3 @@ Recent Changes (arrayvec)
- Added method .into_inner()
- Added unsafe method .set_len()
License
=======
Dual-licensed to be compatible with the Rust project.
Licensed under the Apache License, Version 2.0
http://www.apache.org/licenses/LICENSE-2.0 or the MIT license
http://opensource.org/licenses/MIT, at your
option. This file may not be copied, modified, or distributed
except according to those terms.
......@@ -13,7 +13,7 @@
[package]
edition = "2018"
name = "arrayvec"
version = "0.5.1"
version = "0.5.2"
authors = ["bluss"]
description = "A vector with fixed capacity, backed by an array (it can be stored on the stack too). Implements fixed capacity ArrayVec and ArrayString."
documentation = "https://docs.rs/arrayvec/"
......@@ -60,3 +60,4 @@ array-sizes-129-255 = []
array-sizes-33-128 = []
default = ["std"]
std = []
unstable-const-fn = []
arrayvec
========
[![Crates.io: arrayvec](https://img.shields.io/crates/v/arrayvec.svg)](https://crates.io/crates/arrayvec)
[![Crates.io: nodrop](https://img.shields.io/crates/v/nodrop.svg)](https://crates.io/crates/nodrop)
[![Documentation](https://docs.rs/arrayvec/badge.svg)](https://docs.rs/arrayvec)
[![Build Status](https://travis-ci.org/bluss/arrayvec.svg?branch=master)](https://travis-ci.org/bluss/arrayvec)
[![License: Apache](https://img.shields.io/badge/License-Apache%202.0-red.svg)](LICENSE-APACHE)
OR
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
A vector with fixed capacity.
Please read the [`API documentation here`](https://docs.rs/arrayvec)
# License
Dual-licensed to be compatible with the Rust project.
Licensed under the Apache License, Version 2.0
http://www.apache.org/licenses/LICENSE-2.0 or the MIT license
http://opensource.org/licenses/MIT, at your
option. This file may not be copied, modified, or distributed
except according to those terms.
#!/usr/bin/env sh
set -ex
export CARGO_NET_RETRY=5
export CARGO_NET_TIMEOUT=10
MIRI_NIGHTLY=nightly-$(curl -s https://rust-lang.github.io/rustup-components-history/x86_64-unknown-linux-gnu/miri)
echo "Installing latest nightly with Miri: $MIRI_NIGHTLY"
rustup default "$MIRI_NIGHTLY"
rustup component add miri
cargo miri setup
cargo miri test
......@@ -34,11 +34,13 @@ pub unsafe trait Array {
}
pub trait Index : PartialEq + Copy {
const ZERO: Self;
fn to_usize(self) -> usize;
fn from(_: usize) -> Self;
}
impl Index for () {
const ZERO: Self = ();
#[inline(always)]
fn to_usize(self) -> usize { 0 }
#[inline(always)]
......@@ -46,6 +48,7 @@ impl Index for () {
}
impl Index for bool {
const ZERO: Self = false;
#[inline(always)]
fn to_usize(self) -> usize { self as usize }
#[inline(always)]
......@@ -53,6 +56,7 @@ impl Index for bool {
}
impl Index for u8 {
const ZERO: Self = 0;
#[inline(always)]
fn to_usize(self) -> usize { self as usize }
#[inline(always)]
......@@ -60,6 +64,7 @@ impl Index for u8 {
}
impl Index for u16 {
const ZERO: Self = 0;
#[inline(always)]
fn to_usize(self) -> usize { self as usize }
#[inline(always)]
......@@ -67,6 +72,7 @@ impl Index for u16 {
}
impl Index for u32 {
const ZERO: Self = 0;
#[inline(always)]
fn to_usize(self) -> usize { self as usize }
#[inline(always)]
......@@ -74,6 +80,7 @@ impl Index for u32 {
}
impl Index for usize {
const ZERO: Self = 0;
#[inline(always)]
fn to_usize(self) -> usize { self }
#[inline(always)]
......
......@@ -58,11 +58,22 @@ impl<A> ArrayString<A>
/// assert_eq!(&string[..], "foo");
/// assert_eq!(string.capacity(), 16);
/// ```
#[cfg(not(feature="unstable-const-fn"))]
pub fn new() -> ArrayString<A> {
unsafe {
ArrayString {
xs: MaybeUninitCopy::uninitialized(),
len: Index::from(0),
len: Index::ZERO,
}
}
}
#[cfg(feature="unstable-const-fn")]
pub const fn new() -> ArrayString<A> {
unsafe {
ArrayString {
xs: MaybeUninitCopy::uninitialized(),
len: Index::ZERO,
}
}
}
......@@ -71,6 +82,10 @@ impl<A> ArrayString<A>
#[inline]
pub fn len(&self) -> usize { self.len.to_usize() }
/// Returns whether the string is empty.
#[inline]
pub fn is_empty(&self) -> bool { self.len() == 0 }
/// Create a new `ArrayString` from a `str`.
///
/// Capacity is inferred from the type parameter.
......@@ -226,7 +241,7 @@ impl<A> ArrayString<A>
return Err(CapacityError::new(s));
}
unsafe {
let dst = self.xs.ptr_mut().offset(self.len() as isize);
let dst = self.xs.ptr_mut().add(self.len());
let src = s.as_ptr();
ptr::copy_nonoverlapping(src, dst, s.len());
let newl = self.len() + s.len();
......@@ -317,8 +332,8 @@ impl<A> ArrayString<A>
let next = idx + ch.len_utf8();
let len = self.len();
unsafe {
ptr::copy(self.xs.ptr().offset(next as isize),
self.xs.ptr_mut().offset(idx as isize),
ptr::copy(self.xs.ptr().add(next),
self.xs.ptr_mut().add(idx),
len - next);
self.set_len(len - (next - idx));
}
......
......@@ -63,6 +63,7 @@ pub unsafe fn encode_utf8(ch: char, ptr: *mut u8, len: usize) -> Result<usize, E
#[test]
#[cfg_attr(miri, ignore)] // Miri is too slow
fn test_encode_utf8() {
// Test that all codepoints are encoded correctly
let mut data = [0u8; 16];
......
......@@ -33,11 +33,7 @@ const CAPERROR: &'static str = "insufficient capacity";
#[cfg(feature="std")]
/// Requires `features="std"`.
impl<T: Any> Error for CapacityError<T> {
fn description(&self) -> &str {
CAPERROR
}
}
impl<T: Any> Error for CapacityError<T> {}
impl<T> fmt::Display for CapacityError<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
......
......@@ -14,12 +14,19 @@
//! - Optional
//! - Enable more array sizes (see [Array] for more information)
//!
//! - `unstable-const-fn`
//! - Optional
//! - Makes [`ArrayVec::new`] and [`ArrayString::new`] `const fn`s,
//! using the nightly `const_fn` feature.
//! - Unstable and requires nightly.
//!
//! ## Rust Version
//!
//! This version of arrayvec requires Rust 1.36 or later.
//!
#![doc(html_root_url="https://docs.rs/arrayvec/0.4/")]
#![cfg_attr(not(feature="std"), no_std)]
#![cfg_attr(feature="unstable-const-fn", feature(const_fn))]
#[cfg(feature="serde")]
extern crate serde;
......@@ -81,9 +88,7 @@ impl<A: Array> Drop for ArrayVec<A> {
fn drop(&mut self) {
self.clear();
// NoDrop inhibits array's drop
// panic safety: NoDrop::drop will trigger on panic, so the inner
// array will not drop even after panic.
// MaybeUninit inhibits array's drop
}
}
......@@ -108,9 +113,17 @@ impl<A: Array> ArrayVec<A> {
/// assert_eq!(&array[..], &[1, 2]);
/// assert_eq!(array.capacity(), 16);
/// ```
#[cfg(not(feature="unstable-const-fn"))]
pub fn new() -> ArrayVec<A> {
unsafe {
ArrayVec { xs: MaybeUninit::uninitialized(), len: Index::from(0) }
ArrayVec { xs: MaybeUninit::uninitialized(), len: Index::ZERO }
}
}
#[cfg(feature="unstable-const-fn")]
pub const fn new() -> ArrayVec<A> {
unsafe {
ArrayVec { xs: MaybeUninit::uninitialized(), len: Index::ZERO }
}
}
......@@ -126,6 +139,18 @@ impl<A: Array> ArrayVec<A> {
#[inline]
pub fn len(&self) -> usize { self.len.to_usize() }
/// Returns whether the `ArrayVec` is empty.
///
/// ```
/// use arrayvec::ArrayVec;
///
/// let mut array = ArrayVec::from([1]);
/// array.pop();
/// assert_eq!(array.is_empty(), true);
/// ```
#[inline]
pub fn is_empty(&self) -> bool { self.len() == 0 }
/// Return the capacity of the `ArrayVec`.
///
/// ```
......@@ -545,7 +570,7 @@ impl<A: Array> ArrayVec<A> {
let other_len = other.len();
unsafe {
let dst = self.xs.ptr_mut().offset(self_len as isize);
let dst = self.xs.ptr_mut().add(self_len);
ptr::copy_nonoverlapping(other.as_ptr(), dst, other_len);
self.set_len(self_len + other_len);
}
......@@ -600,12 +625,15 @@ impl<A: Array> ArrayVec<A> {
fn drain_range(&mut self, start: usize, end: usize) -> Drain<A>
{
let len = self.len();
// bounds check happens here
// bounds check happens here (before length is changed!)
let range_slice: *const _ = &self[start..end];
// Calling `set_len` creates a fresh and thus unique mutable references, making all
// older aliases we created invalid. So we cannot call that function.
self.len = Index::from(start);
unsafe {
// set self.vec length's to start, to be safe in case Drain is leaked
self.set_len(start);
Drain {
tail_start: end,
tail_len: len - end,
......@@ -695,6 +723,35 @@ impl<A: Array> From<A> for ArrayVec<A> {
}
/// Try to create an `ArrayVec` from a slice. This will return an error if the slice was too big to
/// fit.
///
/// ```
/// use arrayvec::ArrayVec;
/// use std::convert::TryInto as _;
///
/// let array: ArrayVec<[_; 4]> = (&[1, 2, 3] as &[_]).try_into().unwrap();
/// assert_eq!(array.len(), 3);
/// assert_eq!(array.capacity(), 4);
/// ```