pinned_vec

Crates.iopinned_vec
lib.rspinned_vec
version0.1.1
sourcesrc
created_at2021-11-25 05:28:01.75528
updated_at2021-11-25 05:38:43.40216
descriptionVec-like data structure whose elements never move.
homepage
repositoryhttps://github.com/wishawa/decurse
max_upload_size
id487429
size8,682
Wisha W. (wishawa)

documentation

https://docs.rs/pinned_vec

README

PinnedVec

crates.io crates.io

Vec-like structure whose elements never move.

Normal Vec holds all its content in one contigious region, and moves when it needs to expand. PinnedVec holds several smaller sub-vector, each of which never moves. The first sub-vector is of capacity 1, the second 2, the third 4, the nth 2^(n-1).

Example Usage

use pinned_vec::PinnedVec;
use std::pin::Pin;
let mut v = PinnedVec::new();
v.push(5);
{
	let r: Pin<&i32> = v.get(0).unwrap();
	assert_eq!(*r, 5);
}
{
	let r: Pin<&mut i32> = v.get_mut(0).unwrap();
	assert_eq!(*r, 5);
}
assert_eq!(v.len(), 1);
v.pop();
v.push(7);
v.push(8);
v.replace(0, 6);
assert_eq!(*v.get(0).unwrap(), 6);
assert_eq!(*v.get(1).unwrap(), 8);
Commit count: 45

cargo fmt