Skip to main content

small_collections/
small_collections.rs

1//! Small inline-or-heap collections with a `Vec`/`String`-like API.
2//!
3//! This crate provides two containers that keep short sequences on the stack
4//! and automatically spill onto the heap once they outgrow their inline
5//! capacity:
6//!
7//! * [`SmallVec`] — a vector that stores its first `N` elements inline.
8//! * [`SmallString`] — a string that stores its first `N` bytes inline.
9//!
10//! Both dereference to their standard-library counterparts (`[T]` and `str`
11//! respectively), so the usual slice and string methods are available.
12//!
13//! # Examples
14//!
15//! ```
16//! use small_collections::{SmallString, SmallVec};
17//!
18//! let mut v: SmallVec<i32, 4> = SmallVec::new();
19//! v.extend([1, 2, 3]);
20//! assert!(v.is_inline());
21//!
22//! let mut s: SmallString<8> = SmallString::new();
23//! s.push_str("hello");
24//! assert!(s.is_inline());
25//! ```
26//!
27//! # Feature flags
28//!
29//! * `std` (default) — enables the standard library and the
30//!   `std::io::Write` implementation for `SmallVec<u8, N>`.
31//! * `serde` — enables `Serialize`/`Deserialize`. `SmallVec` serializes as a
32//!   flat sequence and `SmallString` as a plain string, regardless of the
33//!   underlying storage.
34//! * `bytes` — enables the `bytes::BufMut` implementation for
35//!   `SmallVec<u8, N>`.
36
37#![cfg_attr(not(feature = "std"), no_std)]
38
39extern crate alloc;
40
41mod small_string;
42mod small_vec;
43
44pub use small_string::SmallString;
45pub use small_vec::{Drain, IntoIter, SmallVec};