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.17
to
0.3.18
+1
-1
Cargo.toml
[package]
name = "arrayvec"
version = "0.3.17"
version = "0.3.18"
authors = ["bluss"]

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

@@ -6,3 +6,3 @@ DOCCRATES = arrayvec nodrop nodrop_union odds

FEATURES = "odds/unstable nodrop/use_union"
FEATURES = "odds/unstable"

@@ -26,2 +26,3 @@ VERSIONS = $(patsubst %,target/VERS/%,$(DOCCRATES))

cargo doc --features=$(FEATURES)
cargo doc --features=use_union -p nodrop-union
rm -rf ./doc

@@ -28,0 +29,0 @@ cp -r ./target/doc ./doc

@@ -25,2 +25,8 @@

- 0.3.18
- 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

@@ -27,0 +33,0 @@

@@ -182,2 +182,6 @@ //! **arrayvec** provides the types `ArrayVec` and `ArrayString`:

///
/// `index` must be <= `self.len()` and < `self.capacity()`. Note that any
/// out of bounds index insert results in the element being "shifted out"
/// and returned directly.
///
/// ```

@@ -196,3 +200,3 @@ /// use arrayvec::ArrayVec;

pub fn insert(&mut self, index: usize, element: A::Item) -> Option<A::Item> {
if index >= self.capacity() {
if index > self.len() || index == self.capacity() {
return Some(element);

@@ -199,0 +203,0 @@ }

@@ -358,1 +358,58 @@ extern crate arrayvec;

}
#[test]
fn test_insert_at_length() {
let mut v = ArrayVec::<[_; 8]>::new();
let result1 = v.insert(0, "a");
let result2 = v.insert(1, "b");
assert!(result1.is_none() && result2.is_none());
assert_eq!(&v[..], &["a", "b"]);
}
#[test]
fn test_insert_out_of_bounds() {
let mut v = ArrayVec::<[_; 8]>::new();
let result = v.insert(1, "test");
assert_eq!(result, Some("test"));
assert_eq!(v.len(), 0);
let mut u = ArrayVec::from([1, 2, 3, 4]);
let ret = u.insert(3, 99);
assert_eq!(&u[..], &[1, 2, 3, 99]);
assert_eq!(ret, Some(4));
let ret = u.insert(4, 77);
assert_eq!(&u[..], &[1, 2, 3, 99]);
assert_eq!(ret, Some(77));
}
#[test]
fn test_drop_in_insert() {
use std::cell::Cell;
let flag = &Cell::new(0);
struct Bump<'a>(&'a Cell<i32>);
impl<'a> Drop for Bump<'a> {
fn drop(&mut self) {
let n = self.0.get();
self.0.set(n + 1);
}
}
flag.set(0);
{
let mut array = ArrayVec::<[_; 2]>::new();
array.push(Bump(flag));
array.insert(0, Bump(flag));
assert_eq!(flag.get(), 0);
let ret = array.insert(1, Bump(flag));
assert_eq!(flag.get(), 0);
assert!(ret.is_some());
drop(ret);
assert_eq!(flag.get(), 1);
}
assert_eq!(flag.get(), 3);
}