Expand description
Small inline-or-heap collections with a Vec/String-like API.
This crate provides two containers that keep short sequences on the stack and automatically spill onto the heap once they outgrow their inline capacity:
SmallVec— a vector that stores its firstNelements inline.SmallString— a string that stores its firstNbytes inline.
Both dereference to their standard-library counterparts ([T] and str
respectively), so the usual slice and string methods are available.
§Examples
use small_collections::{SmallString, SmallVec};
let mut v: SmallVec<i32, 4> = SmallVec::new();
v.extend([1, 2, 3]);
assert!(v.is_inline());
let mut s: SmallString<8> = SmallString::new();
s.push_str("hello");
assert!(s.is_inline());§Feature flags
std(default) — enables the standard library and thestd::io::Writeimplementation forSmallVec<u8, N>.serde— enablesSerialize/Deserialize.SmallVecserializes as a flat sequence andSmallStringas a plain string, regardless of the underlying storage.bytes— enables thebytes::BufMutimplementation forSmallVec<u8, N>.
Enums§
- Drain
- A draining iterator for a
SmallVec. - Into
Iter - An iterator that moves elements out of a
SmallVec. - Small
String - A string that stores up to
Nbytes inline (on the stack) and spills onto the heap once it grows past that inline capacity. - Small
Vec - A vector that stores its first
Nelements inline (on the stack) and spills onto the heap once it grows past that inline capacity.