pub union SmallBytes {
/* private fields */
}Expand description
A 24-byte owned byte string with inline small-string optimization.
Strings of up to 22 bytes live entirely inside the value (no allocation, no pointer chase); larger strings spill to a heap buffer. The discriminator is a single byte at offset 23 (the tag, which doubles as the inline length 0..=22 OR equals 0xFF when the heap variant is active).
See the crate root for layout details.
Implementations§
Source§impl SmallBytes
impl SmallBytes
Sourcepub const fn new() -> SmallBytes
pub const fn new() -> SmallBytes
Empty inline SmallBytes (zero allocation).
Sourcepub fn from_slice(bytes: &[u8]) -> SmallBytes
pub fn from_slice(bytes: &[u8]) -> SmallBytes
Construct from a byte slice — inline if bytes.len() <= 22, else heap.
Sourcepub fn from_vec(vec: Vec<u8>) -> SmallBytes
pub fn from_vec(vec: Vec<u8>) -> SmallBytes
Take ownership of a Vec<u8> — inline if vec.len() <= 22, else reuse
the vec’s allocation (no copy on the heap path).
Sourcepub fn heap_bytes(&self) -> usize
pub fn heap_bytes(&self) -> usize
Bytes this value holds on the heap (0 when inline). Lets memory-accounting
callers (e.g. maxmemory enforcement) charge only the off-stack footprint
without re-deriving the inline-length threshold.
Trait Implementations§
Source§impl AsRef<[u8]> for SmallBytes
impl AsRef<[u8]> for SmallBytes
Source§impl Borrow<[u8]> for SmallBytes
impl Borrow<[u8]> for SmallBytes
Source§impl Clone for SmallBytes
impl Clone for SmallBytes
Source§fn clone(&self) -> SmallBytes
fn clone(&self) -> SmallBytes
Specialised clone that bypasses as_slice → from_slice → alloc_heap’s
two layered length checks. Inline variant is a bitwise union copy (no
branch through the slice path); heap variant goes straight to a single
alloc + memcpy keyed on the already-known heap length.
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SmallBytes
impl Debug for SmallBytes
Source§impl Default for SmallBytes
impl Default for SmallBytes
Source§fn default() -> SmallBytes
fn default() -> SmallBytes
Source§impl Drop for SmallBytes
impl Drop for SmallBytes
impl Eq for SmallBytes
Source§impl From<&[u8]> for SmallBytes
impl From<&[u8]> for SmallBytes
Source§fn from(bytes: &[u8]) -> SmallBytes
fn from(bytes: &[u8]) -> SmallBytes
Source§impl Hash for SmallBytes
impl Hash for SmallBytes
Source§impl KevyHash for SmallBytes
KevyHash agrees with the byte-slice impl, so a KevyMap<SmallBytes, V>
can be queried with &[u8] (via Borrow<[u8]>) and the hash matches.
impl KevyHash for SmallBytes
KevyHash agrees with the byte-slice impl, so a KevyMap<SmallBytes, V>
can be queried with &[u8] (via Borrow<[u8]>) and the hash matches.
Source§impl Ord for SmallBytes
impl Ord for SmallBytes
Source§fn cmp(&self, other: &SmallBytes) -> Ordering
fn cmp(&self, other: &SmallBytes) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for SmallBytes
impl PartialEq for SmallBytes
Source§fn eq(&self, other: &SmallBytes) -> bool
fn eq(&self, other: &SmallBytes) -> bool
Specialised over the slice form (as_slice == as_slice) by branching
on variant once and reading the relevant length / pointer pair
directly. Same-variant cases (inline/inline + heap/heap, which are the
only ones produced by a single allocator) skip a redundant as_slice
dispatch on each side; the mixed case falls back to the slice form.