Skip to content

Commit c7424b8

Browse files
authored
Merge pull request #129 from bluss/prepare-0.5
Always use MaybeUninit and stop using nodrop fallback, prepare next release
2 parents 6ed5b7b + 470cfd2 commit c7424b8

12 files changed

+49
-297
lines changed

.travis.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ env:
44
- FEATURES='serde-1'
55
matrix:
66
include:
7-
- rust: 1.24.1
7+
- rust: 1.36.0
88
env:
99
- FEATURES='array-sizes-33-128 array-sizes-129-255'
1010
- rust: stable
@@ -14,23 +14,17 @@ matrix:
1414
- rust: stable
1515
env:
1616
- FEATURES='array-sizes-33-128 array-sizes-129-255'
17-
- ARRAYVECTEST_ENSURE_MAYBEUNINIT=1
1817
- rust: beta
1918
- rust: nightly
20-
env:
21-
- ARRAYVECTEST_ENSURE_UNION=1
2219
- rust: nightly
2320
env:
2421
- FEATURES='serde'
25-
- ARRAYVECTEST_ENSURE_UNION=1
2622
- rust: nightly
2723
env:
2824
- FEATURES='serde-1'
29-
- ARRAYVECTEST_ENSURE_UNION=1
3025
- rust: nightly
3126
env:
3227
- FEATURES='array-sizes-33-128 array-sizes-129-255'
33-
- ARRAYVECTEST_ENSURE_MAYBEUNINIT=1
3428
branches:
3529
only:
3630
- master

Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ categories = ["data-structures", "no-std"]
1313

1414
[build-dependencies]
1515

16-
[dependencies]
17-
nodrop = { version = "0.1.12", path = "nodrop", default-features = false }
18-
1916
[dependencies.serde]
2017
version = "1.0"
2118
optional = true

README.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ __ https://docs.rs/arrayvec
2222
Recent Changes (arrayvec)
2323
-------------------------
2424

25+
- 0.5.0 (not released yet)
26+
27+
- Add ``FromStr`` impl for ``ArrayString`` by @despawnerer
28+
- Use a union in the implementation of ``ArrayString`` (stable Rust),
29+
while this is only used for ``ArrayVec`` on nightly.
30+
- Add method ``try_extend_from_slice`` to ``ArrayVec``, which is always
31+
effecient by @Thomasdezeeuw.
32+
- Add method ``remaining_capacity`` by @Thomasdezeeuw
33+
- Improve performance of the ``extend`` method.
34+
- The index type of zero capacity vectors is now itself zero size, by
35+
@clarcharr
36+
- Use ``drop_in_place`` for truncate and clear methods. This affects drop order
37+
and resume from panic during drop.
38+
2539
- 0.4.11
2640

2741
- In Rust 1.36 or later, use newly stable MaybeUninit. This extends the

build.rs

Lines changed: 0 additions & 90 deletions
This file was deleted.

src/array.rs

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,15 @@ pub unsafe trait Array {
2020
type Index: Index;
2121
/// The array's element capacity
2222
const CAPACITY: usize;
23-
#[doc(hidden)]
24-
fn as_ptr(&self) -> *const Self::Item;
25-
#[doc(hidden)]
26-
fn capacity() -> usize;
23+
fn as_slice(&self) -> &[Self::Item];
24+
fn as_mut_slice(&mut self) -> &mut [Self::Item];
2725
}
2826

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

34-
use std::slice::{from_raw_parts};
35-
36-
pub trait ArrayExt : Array {
37-
#[inline(always)]
38-
fn as_slice(&self) -> &[Self::Item] {
39-
unsafe {
40-
from_raw_parts(self.as_ptr(), Self::capacity())
41-
}
42-
}
43-
}
44-
45-
impl<A> ArrayExt for A where A: Array { }
46-
4732
impl Index for () {
4833
#[inline(always)]
4934
fn to_usize(self) -> usize { 0 }
@@ -93,11 +78,11 @@ macro_rules! fix_array_impl {
9378
type Index = $index_type;
9479
const CAPACITY: usize = $len;
9580
#[doc(hidden)]
96-
#[inline(always)]
97-
fn as_ptr(&self) -> *const T { self as *const _ as *const _ }
81+
#[inline]
82+
fn as_slice(&self) -> &[Self::Item] { self }
9883
#[doc(hidden)]
99-
#[inline(always)]
100-
fn capacity() -> usize { $len }
84+
#[inline]
85+
fn as_mut_slice(&mut self) -> &mut [Self::Item] { self }
10186
}
10287
)
10388
}

src/array_string.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ use std::str::FromStr;
99
use std::str::Utf8Error;
1010
use std::slice;
1111

12-
use array::{Array, ArrayExt};
12+
use array::Array;
1313
use array::Index;
1414
use CapacityError;
1515
use char::encode_utf8;
1616

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

20-
use super::MaybeUninitCopy;
20+
use super::MaybeUninit as MaybeUninitCopy;
2121

2222
/// A string with a fixed capacity.
2323
///
@@ -98,10 +98,10 @@ impl<A> ArrayString<A>
9898
/// ```
9999
pub fn from_byte_string(b: &A) -> Result<Self, Utf8Error> {
100100
let len = str::from_utf8(b.as_slice())?.len();
101-
debug_assert_eq!(len, A::capacity());
101+
debug_assert_eq!(len, A::CAPACITY);
102102
Ok(ArrayString {
103103
xs: MaybeUninitCopy::from(*b),
104-
len: Index::from(A::capacity()),
104+
len: Index::from(A::CAPACITY),
105105
})
106106
}
107107

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

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

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

553553
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>

src/lib.rs

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
//!
1717
//! ## Rust Version
1818
//!
19-
//! This version of arrayvec requires Rust 1.24 or later.
19+
//! This version of arrayvec requires Rust 1.36 or later.
2020
//!
2121
#![doc(html_root_url="https://docs.rs/arrayvec/0.4/")]
2222
#![cfg_attr(not(feature="std"), no_std)]
@@ -28,9 +28,6 @@ extern crate serde;
2828
#[cfg(not(feature="std"))]
2929
extern crate core as std;
3030

31-
#[cfg(not(has_manually_drop_in_union))]
32-
extern crate nodrop;
33-
3431
use std::cmp;
3532
use std::iter;
3633
use std::mem;
@@ -50,19 +47,8 @@ use std::fmt;
5047
use std::io;
5148

5249

53-
#[cfg(has_stable_maybe_uninit)]
54-
#[path="maybe_uninit_stable.rs"]
55-
mod maybe_uninit;
56-
#[cfg(all(not(has_stable_maybe_uninit), has_manually_drop_in_union))]
57-
mod maybe_uninit;
58-
#[cfg(all(not(has_stable_maybe_uninit), not(has_manually_drop_in_union)))]
59-
#[path="maybe_uninit_nodrop.rs"]
6050
mod maybe_uninit;
61-
62-
mod maybe_uninit_copy;
63-
6451
use maybe_uninit::MaybeUninit;
65-
use maybe_uninit_copy::MaybeUninitCopy;
6652

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

160146
/// Return if the `ArrayVec` is completely filled.
161147
///
@@ -223,7 +209,7 @@ impl<A: Array> ArrayVec<A> {
223209
/// assert!(overflow.is_err());
224210
/// ```
225211
pub fn try_push(&mut self, element: A::Item) -> Result<(), CapacityError<A::Item>> {
226-
if self.len() < A::capacity() {
212+
if self.len() < A::CAPACITY {
227213
unsafe {
228214
self.push_unchecked(element);
229215
}
@@ -258,7 +244,7 @@ impl<A: Array> ArrayVec<A> {
258244
#[inline]
259245
pub unsafe fn push_unchecked(&mut self, element: A::Item) {
260246
let len = self.len();
261-
debug_assert!(len < A::capacity());
247+
debug_assert!(len < A::CAPACITY);
262248
ptr::write(self.get_unchecked_mut(len), element);
263249
self.set_len(len + 1);
264250
}
@@ -680,7 +666,7 @@ impl<A: Array> DerefMut for ArrayVec<A> {
680666
/// ```
681667
impl<A: Array> From<A> for ArrayVec<A> {
682668
fn from(array: A) -> Self {
683-
ArrayVec { xs: MaybeUninit::from(array), len: Index::from(A::capacity()) }
669+
ArrayVec { xs: MaybeUninit::from(array), len: Index::from(A::CAPACITY) }
684670
}
685671
}
686672

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

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

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

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

0 commit comments

Comments
 (0)