🎩 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.6
to
0.3.7
+1
-1
Cargo.toml
[package]
name = "arrayvec"
version = "0.3.6"
version = "0.3.7"
authors = ["bluss"]

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

@@ -22,2 +22,10 @@

Recent Changes
--------------
- 0.3.7
- Added method .into_inner()
- Added unsafe method .set_len()
License

@@ -24,0 +32,0 @@ =======

@@ -93,7 +93,2 @@ extern crate odds;

unsafe fn set_len(&mut self, length: usize) {
debug_assert!(length <= self.capacity());
self.len = Index::from(length);
}
/// Return the capacity of the **ArrayVec**.

@@ -269,2 +264,15 @@ ///

/// Set the vector's length without dropping or moving out elements
///
/// May panic if **length** is greater than the capacity.
///
/// This function is **unsafe** because it changes the notion of the
/// number of “valid” elements in the vector. Use with care.
#[inline]
pub unsafe fn set_len(&mut self, length: usize) {
debug_assert!(length <= self.capacity());
self.len = Index::from(length);
}
/// Create a draining iterator that removes the specified range in the vector

@@ -320,2 +328,21 @@ /// and yields the removed items from start to end. The element range is

}
/// Return the inner fixed size array, if it is full to its capacity.
///
/// 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
/// to move the array out, its performance is not optimal.
pub fn into_inner(self) -> Result<A, Self> {
if self.len() < self.capacity() {
Err(self)
} else {
unsafe {
let array = ptr::read(&*self.xs);
mem::forget(self);
Ok(array)
}
}
}
}

@@ -322,0 +349,0 @@

@@ -86,2 +86,17 @@ extern crate arrayvec;

assert_eq!(flag.get(), 4);
// test into_inner
flag.set(0);
{
let mut array = ArrayVec::<[_; 3]>::new();
array.push(Bump(flag));
array.push(Bump(flag));
array.push(Bump(flag));
let inner = array.into_inner();
assert!(inner.is_ok());
assert_eq!(flag.get(), 0);
drop(inner);
assert_eq!(flag.get(), 3);
}
}

@@ -182,1 +197,26 @@

}
#[test]
fn test_into_inner_1() {
let mut v = ArrayVec::from([1, 2]);
v.pop();
let u = v.clone();
assert_eq!(v.into_inner(), Err(u));
}
#[test]
fn test_into_inner_2() {
let mut v = ArrayVec::<[String; 4]>::new();
v.push("a".into());
v.push("b".into());
v.push("c".into());
v.push("d".into());
assert_eq!(v.into_inner().unwrap(), ["a", "b", "c", "d"]);
}
#[test]
fn test_into_inner_3_() {
let mut v = ArrayVec::<[i32; 4]>::new();
v.extend(1..);
assert_eq!(v.into_inner().unwrap(), [1, 2, 3, 4]);
}