Skip to content

Always use MaybeUninit and stop using nodrop fallback, prepare next release #129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ env:
- FEATURES='serde-1'
matrix:
include:
- rust: 1.24.1
- rust: 1.36.0
env:
- FEATURES='array-sizes-33-128 array-sizes-129-255'
- rust: stable
Expand All @@ -14,23 +14,17 @@ matrix:
- rust: stable
env:
- FEATURES='array-sizes-33-128 array-sizes-129-255'
- ARRAYVECTEST_ENSURE_MAYBEUNINIT=1
- rust: beta
- rust: nightly
env:
- ARRAYVECTEST_ENSURE_UNION=1
- rust: nightly
env:
- FEATURES='serde'
- ARRAYVECTEST_ENSURE_UNION=1
- rust: nightly
env:
- FEATURES='serde-1'
- ARRAYVECTEST_ENSURE_UNION=1
- rust: nightly
env:
- FEATURES='array-sizes-33-128 array-sizes-129-255'
- ARRAYVECTEST_ENSURE_MAYBEUNINIT=1
branches:
only:
- master
Expand Down
3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ categories = ["data-structures", "no-std"]

[build-dependencies]

[dependencies]
nodrop = { version = "0.1.12", path = "nodrop", default-features = false }

[dependencies.serde]
version = "1.0"
optional = true
Expand Down
14 changes: 14 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ __ https://docs.rs/arrayvec
Recent Changes (arrayvec)
-------------------------

- 0.5.0 (not released yet)

- Add ``FromStr`` impl for ``ArrayString`` by @despawnerer
- Use a union in the implementation of ``ArrayString`` (stable Rust),
while this is only used for ``ArrayVec`` on nightly.
- 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.
- The index type of zero capacity vectors is now itself zero size, by
@clarcharr
- Use ``drop_in_place`` for truncate and clear methods. This affects drop order
and resume from panic during drop.

- 0.4.11

- In Rust 1.36 or later, use newly stable MaybeUninit. This extends the
Expand Down
90 changes: 0 additions & 90 deletions build.rs

This file was deleted.

27 changes: 6 additions & 21 deletions src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,15 @@ pub unsafe trait Array {
type Index: Index;
/// The array's element capacity
const CAPACITY: usize;
#[doc(hidden)]
fn as_ptr(&self) -> *const Self::Item;
#[doc(hidden)]
fn capacity() -> usize;
fn as_slice(&self) -> &[Self::Item];
fn as_mut_slice(&mut self) -> &mut [Self::Item];
}

pub trait Index : PartialEq + Copy {
fn to_usize(self) -> usize;
fn from(usize) -> Self;
}

use std::slice::{from_raw_parts};

pub trait ArrayExt : Array {
#[inline(always)]
fn as_slice(&self) -> &[Self::Item] {
unsafe {
from_raw_parts(self.as_ptr(), Self::capacity())
}
}
}

impl<A> ArrayExt for A where A: Array { }

impl Index for () {
#[inline(always)]
fn to_usize(self) -> usize { 0 }
Expand Down Expand Up @@ -93,11 +78,11 @@ macro_rules! fix_array_impl {
type Index = $index_type;
const CAPACITY: usize = $len;
#[doc(hidden)]
#[inline(always)]
fn as_ptr(&self) -> *const T { self as *const _ as *const _ }
#[inline]
fn as_slice(&self) -> &[Self::Item] { self }
#[doc(hidden)]
#[inline(always)]
fn capacity() -> usize { $len }
#[inline]
fn as_mut_slice(&mut self) -> &mut [Self::Item] { self }
}
)
}
Expand Down
12 changes: 6 additions & 6 deletions src/array_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ use std::str::FromStr;
use std::str::Utf8Error;
use std::slice;

use array::{Array, ArrayExt};
use array::Array;
use array::Index;
use CapacityError;
use char::encode_utf8;

#[cfg(feature="serde-1")]
use serde::{Serialize, Deserialize, Serializer, Deserializer};

use super::MaybeUninitCopy;
use super::MaybeUninit as MaybeUninitCopy;

/// A string with a fixed capacity.
///
Expand Down Expand Up @@ -98,10 +98,10 @@ impl<A> ArrayString<A>
/// ```
pub fn from_byte_string(b: &A) -> Result<Self, Utf8Error> {
let len = str::from_utf8(b.as_slice())?.len();
debug_assert_eq!(len, A::capacity());
debug_assert_eq!(len, A::CAPACITY);
Ok(ArrayString {
xs: MaybeUninitCopy::from(*b),
len: Index::from(A::capacity()),
len: Index::from(A::CAPACITY),
})
}

Expand All @@ -114,7 +114,7 @@ impl<A> ArrayString<A>
/// assert_eq!(string.capacity(), 3);
/// ```
#[inline]
pub fn capacity(&self) -> usize { A::capacity() }
pub fn capacity(&self) -> usize { A::CAPACITY }

/// Return if the `ArrayString` is completely filled.
///
Expand Down Expand Up @@ -547,7 +547,7 @@ impl<'de, A> Deserialize<'de> for ArrayString<A>
type Value = ArrayString<A>;

fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
write!(formatter, "a string no more than {} bytes long", A::capacity())
write!(formatter, "a string no more than {} bytes long", A::CAPACITY)
}

fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
Expand Down
28 changes: 7 additions & 21 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//!
//! ## Rust Version
//!
//! This version of arrayvec requires Rust 1.24 or later.
//! 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)]
Expand All @@ -28,9 +28,6 @@ extern crate serde;
#[cfg(not(feature="std"))]
extern crate core as std;

#[cfg(not(has_manually_drop_in_union))]
extern crate nodrop;

use std::cmp;
use std::iter;
use std::mem;
Expand All @@ -50,19 +47,8 @@ use std::fmt;
use std::io;


#[cfg(has_stable_maybe_uninit)]
#[path="maybe_uninit_stable.rs"]
mod maybe_uninit;
#[cfg(all(not(has_stable_maybe_uninit), has_manually_drop_in_union))]
mod maybe_uninit;
#[cfg(all(not(has_stable_maybe_uninit), not(has_manually_drop_in_union)))]
#[path="maybe_uninit_nodrop.rs"]
mod maybe_uninit;

mod maybe_uninit_copy;

use maybe_uninit::MaybeUninit;
use maybe_uninit_copy::MaybeUninitCopy;

#[cfg(feature="serde-1")]
use serde::{Serialize, Deserialize, Serializer, Deserializer};
Expand Down Expand Up @@ -155,7 +141,7 @@ impl<A: Array> ArrayVec<A> {
/// assert_eq!(array.capacity(), 3);
/// ```
#[inline]
pub fn capacity(&self) -> usize { A::capacity() }
pub fn capacity(&self) -> usize { A::CAPACITY }

/// Return if the `ArrayVec` is completely filled.
///
Expand Down Expand Up @@ -223,7 +209,7 @@ impl<A: Array> ArrayVec<A> {
/// assert!(overflow.is_err());
/// ```
pub fn try_push(&mut self, element: A::Item) -> Result<(), CapacityError<A::Item>> {
if self.len() < A::capacity() {
if self.len() < A::CAPACITY {
unsafe {
self.push_unchecked(element);
}
Expand Down Expand Up @@ -258,7 +244,7 @@ impl<A: Array> ArrayVec<A> {
#[inline]
pub unsafe fn push_unchecked(&mut self, element: A::Item) {
let len = self.len();
debug_assert!(len < A::capacity());
debug_assert!(len < A::CAPACITY);
ptr::write(self.get_unchecked_mut(len), element);
self.set_len(len + 1);
}
Expand Down Expand Up @@ -680,7 +666,7 @@ impl<A: Array> DerefMut for ArrayVec<A> {
/// ```
impl<A: Array> From<A> for ArrayVec<A> {
fn from(array: A) -> Self {
ArrayVec { xs: MaybeUninit::from(array), len: Index::from(A::capacity()) }
ArrayVec { xs: MaybeUninit::from(array), len: Index::from(A::CAPACITY) }
}
}

Expand Down Expand Up @@ -1133,7 +1119,7 @@ impl<'de, T: Deserialize<'de>, A: Array<Item=T>> Deserialize<'de> for ArrayVec<A
type Value = ArrayVec<A>;

fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
write!(formatter, "an array with no more than {} items", A::capacity())
write!(formatter, "an array with no more than {} items", A::CAPACITY)
}

fn visit_seq<SA>(self, mut seq: SA) -> Result<Self::Value, SA::Error>
Expand All @@ -1143,7 +1129,7 @@ impl<'de, T: Deserialize<'de>, A: Array<Item=T>> Deserialize<'de> for ArrayVec<A

while let Some(value) = try!(seq.next_element()) {
if let Err(_) = values.try_push(value) {
return Err(SA::Error::invalid_length(A::capacity() + 1, &self));
return Err(SA::Error::invalid_length(A::CAPACITY + 1, &self));
}
}

Expand Down
Loading