🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

arrayvec

Package Overview
Dependencies
Maintainers
0
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

arrayvec - cargo Package Compare versions

Comparing version
0.3.10
to
0.3.11
+1
-1
Cargo.toml
[package]
name = "arrayvec"
version = "0.3.10"
version = "0.3.11"
authors = ["bluss"]

@@ -5,0 +5,0 @@ license = "MIT/Apache-2.0"

@@ -25,2 +25,6 @@

- 0.3.11
- Added trait impls Default, PartialOrd, Ord, Write for ArrayVec
- 0.3.10

@@ -27,0 +31,0 @@

extern crate odds;
extern crate nodrop;
use std::cmp;
use std::io;
use std::iter;

@@ -36,3 +38,3 @@ use std::mem;

///
/// The **ArrayVec** is a vector backed by a fixed size array. It keeps track of
/// The `ArrayVec` is a vector backed by a fixed size array. It keeps track of
/// the number of initialized elements.

@@ -65,8 +67,6 @@ ///

impl<A: Array> ArrayVec<A> {
/// Create a new empty **ArrayVec**.
/// Create a new empty `ArrayVec`.
///
/// Capacity is inferred from the type parameter.
///
/// ## Examples
///
/// ```

@@ -87,5 +87,4 @@ /// use arrayvec::ArrayVec;

/// Return the number of elements in the **ArrayVec**.
/// Return the number of elements in the `ArrayVec`.
///
/// ## Examples
/// ```

@@ -101,5 +100,4 @@ /// use arrayvec::ArrayVec;

/// Return the capacity of the **ArrayVec**.
/// Return the capacity of the `ArrayVec`.
///
/// ## Examples
/// ```

@@ -114,8 +112,7 @@ /// use arrayvec::ArrayVec;

/// Push **element** to the end of the vector.
/// Push `element` to the end of the vector.
///
/// Return **None** if the push succeeds, or and return **Some(** *element* **)**
/// Return `None` if the push succeeds, or and return `Some(` *element* `)`
/// if the vector is full.
///
/// ## Examples
/// ```

@@ -148,5 +145,4 @@ /// use arrayvec::ArrayVec;

///
/// Return **Some(** *element* **)** if the vector is non-empty, else **None**.
/// Return `Some(` *element* `)` if the vector is non-empty, else `None`.
///
/// ## Examples
/// ```

@@ -173,9 +169,8 @@ /// use arrayvec::ArrayVec;

/// Insert **element** in position **index**.
/// Insert `element` in position `index`.
///
/// Shift up all elements after **index**. If any is pushed out, it is returned.
/// Shift up all elements after `index`. If any is pushed out, it is returned.
///
/// Return None if no element is shifted out.
/// Return `None` if no element is shifted out.
///
/// ## Examples
/// ```

@@ -198,4 +193,3 @@ /// use arrayvec::ArrayVec;

let mut ret = None;
let old_len = self.len();
if old_len == self.capacity() {
if self.len() == self.capacity() {
ret = self.pop();

@@ -209,9 +203,9 @@ }

{
let p = self.as_mut_ptr().offset(index as isize);
let p = self.get_unchecked_mut(index) as *mut _;
// Shift everything over to make space. (Duplicating the
// `index`th element into two consecutive places.)
ptr::copy(&*p, p.offset(1), len - index);
ptr::copy(p, p.offset(1), len - index);
// Write it in, overwriting the first copy of the `index`th
// element.
ptr::write(&mut *p, element);
ptr::write(p, element);
}

@@ -223,9 +217,8 @@ self.set_len(len + 1);

/// Remove the element at **index** and swap the last element into its place.
/// Remove the element at `index` and swap the last element into its place.
///
/// This operation is O(1).
///
/// Return **Some(** *element* **)** if the index is in bounds, else **None**.
/// Return `Some(` *element* `)` if the index is in bounds, else `None`.
///
/// ## Examples
/// ```

@@ -250,7 +243,6 @@ /// use arrayvec::ArrayVec;

/// Remove the element at **index** and shift down the following elements.
/// Remove the element at `index` and shift down the following elements.
///
/// Return **Some(** *element* **)** if the index is in bounds, else **None**.
/// Return `Some(` *element* `)` if the index is in bounds, else `None`.
///
/// ## Examples
/// ```

@@ -281,5 +273,5 @@ /// use arrayvec::ArrayVec;

///
/// May panic if **length** is greater than the capacity.
/// May panic if `length` is greater than the capacity.
///
/// This function is **unsafe** because it changes the notion of the
/// This function is `unsafe` because it changes the notion of the
/// number of “valid” elements in the vector. Use with care.

@@ -300,9 +292,5 @@ #[inline]

///
/// # Panics
///
/// Panics if the starting point is greater than the end point or if
/// **Panics** if the starting point is greater than the end point or if
/// the end point is greater than the length of the vector.
///
/// # Examples
///
/// ```

@@ -347,6 +335,6 @@ /// use arrayvec::ArrayVec;

///
/// Return an **Ok** value with the array if length equals capacity,
/// return an **Err** with self otherwise.
/// Return an `Ok` value with the array if length equals capacity,
/// return an `Err` with self otherwise.
///
/// **Note:** This function may incur unproportionally large overhead
/// `Note:` This function may incur unproportionally large overhead
/// to move the array out, its performance is not optimal.

@@ -386,5 +374,4 @@ pub fn into_inner(self) -> Result<A, Self> {

/// Create an **ArrayVec** from an array.
/// Create an `ArrayVec` from an array.
///
/// ## Examples
/// ```

@@ -404,6 +391,4 @@ /// use arrayvec::ArrayVec;

/// Iterate the **ArrayVec** with references to each element.
/// Iterate the `ArrayVec` with references to each element.
///
/// ## Examples
///
/// ```

@@ -424,6 +409,4 @@ /// use arrayvec::ArrayVec;

/// Iterate the **ArrayVec** with mutable references to each element.
/// Iterate the `ArrayVec` with mutable references to each element.
///
/// ## Examples
///
/// ```

@@ -444,8 +427,6 @@ /// use arrayvec::ArrayVec;

/// Iterate the **ArrayVec** with each element by value.
/// Iterate the `ArrayVec` with each element by value.
///
/// The vector is consumed by this operation.
///
/// ## Examples
///
/// ```

@@ -467,3 +448,3 @@ /// use arrayvec::ArrayVec;

/// By-value iterator for **ArrayVec**.
/// By-value iterator for `ArrayVec`.
pub struct IntoIter<A: Array> {

@@ -529,3 +510,3 @@ index: A::Index,

/// A draining iterator for **ArrayVec**.
/// A draining iterator for `ArrayVec`.
pub struct Drain<'a, A>

@@ -609,3 +590,3 @@ where A: Array,

/// Extend the **ArrayVec** with an iterator.
/// Extend the `ArrayVec` with an iterator.
///

@@ -623,3 +604,3 @@ /// Does not extract more items than there is space for. No error

/// Create an **ArrayVec** from an iterator.
/// Create an `ArrayVec` from an iterator.
///

@@ -681,1 +662,57 @@ /// Does not extract more items than there is space for. No error

}
impl<A: Array> Default for ArrayVec<A> {
fn default() -> ArrayVec<A> {
ArrayVec::new()
}
}
impl<A: Array> PartialOrd for ArrayVec<A> where A::Item: PartialOrd {
#[inline]
fn partial_cmp(&self, other: &ArrayVec<A>) -> Option<cmp::Ordering> {
(**self).partial_cmp(other)
}
#[inline]
fn lt(&self, other: &Self) -> bool {
(**self).lt(other)
}
#[inline]
fn le(&self, other: &Self) -> bool {
(**self).le(other)
}
#[inline]
fn ge(&self, other: &Self) -> bool {
(**self).ge(other)
}
#[inline]
fn gt(&self, other: &Self) -> bool {
(**self).gt(other)
}
}
impl<A: Array> Ord for ArrayVec<A> where A::Item: Ord {
fn cmp(&self, other: &ArrayVec<A>) -> cmp::Ordering {
(**self).cmp(other)
}
}
/// `Write` appends written data to the end of the vector.
impl<A: Array<Item=u8>> io::Write for ArrayVec<A> {
fn write(&mut self, data: &[u8]) -> io::Result<usize> {
unsafe {
let len = self.len();
let mut tail = slice::from_raw_parts_mut(self.get_unchecked_mut(len),
A::capacity() - len);
let result = tail.write(data);
if let Ok(written) = result {
self.set_len(len + written);
}
result
}
}
fn flush(&mut self) -> io::Result<()> { Ok(()) }
}

@@ -252,1 +252,12 @@ extern crate arrayvec;

}
#[test]
fn test_write() {
use std::io::Write;
let mut v = ArrayVec::<[_; 8]>::new();
write!(&mut v, "\x01\x02\x03").unwrap();
assert_eq!(&v[..], &[1, 2, 3]);
let r = v.write(&[9; 16]).unwrap();
assert_eq!(r, 5);
assert_eq!(&v[..], &[1, 2, 3, 9, 9, 9, 9, 9]);
}