Struct rustc_borrowck::SmallVec [−][src]
pub(crate) struct SmallVec<A> where
A: Array, {
pub(crate) capacity: usize,
pub(crate) data: SmallVecData<A>,
}Expand description
A Vec-like container that can store a small number of elements inline.
SmallVec acts like a vector, but can store a limited amount of data inline within the
SmallVec struct rather than in a separate allocation. If the data exceeds this limit, the
SmallVec will “spill” its data onto the heap, allocating a new buffer to hold it.
The amount of data that a SmallVec can store inline depends on its backing store. The backing
store can be any type that implements the Array trait; usually it is a small fixed-sized
array. For example a SmallVec<[u64; 8]> can hold up to eight 64-bit integers inline.
Example
use smallvec::SmallVec;
let mut v = SmallVec::<[u8; 4]>::new(); // initialize an empty vector
// The vector can hold up to 4 items without spilling onto the heap.
v.extend(0..4);
assert_eq!(v.len(), 4);
assert!(!v.spilled());
// Pushing another element will force the buffer to spill:
v.push(4);
assert_eq!(v.len(), 5);
assert!(v.spilled());Fields
capacity: usizedata: SmallVecData<A>Auto Trait Implementations
impl<A> RefUnwindSafe for SmallVec<A> where
A: RefUnwindSafe,
<A as Array>::Item: RefUnwindSafe,
impl<A> UnwindSafe for SmallVec<A> where
A: UnwindSafe,
<A as Array>::Item: RefUnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
Layout
Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.