[−][src]Crate beef
Faster, more compact implementation of Cow
.
Changelog - Cargo - Repository
use beef::Cow; let borrowed: Cow<str> = Cow::borrowed("Hello"); let owned: Cow<str> = Cow::owned(String::from("World")); assert_eq!( format!("{} {}!", borrowed, owned), "Hello World!", );
There are two versions of Cow
exposed by this crate:
beef::Cow
is 3 words wide: pointer, length, and capacity. It stores the ownership tag in capacity.beef::lean::Cow
is 2 words wide, storing length, capacity, and the ownership tag all in one word.
Both versions are leaner than the std::borrow::Cow
:
use std::mem::size_of; const WORD: usize = size_of::<usize>(); assert_eq!(size_of::<std::borrow::Cow<str>>(), 4 * WORD); assert_eq!(size_of::<beef::Cow<str>>(), 3 * WORD); assert_eq!(size_of::<beef::lean::Cow<str>>(), 2 * WORD);
Modules
generic | This module contains the actual, albeit generic, implementaiton of the |
lean | Namespace containing the 2-word |
Type Definitions
Cow | Compact three word |