Expand description

A flexible, simple to use, immutable, clone-efficient String replacement for Rust

use flexstr::{flex_fmt, FlexStr, IntoFlexStr, ToCase, ToFlexStr};

// Use an `into` function to simply wrap a string literal, no allocation or copying
let static_str = "This will not allocate or copy".into_flex_str();
assert!(static_str.is_static());

// Strings up to 22 bytes (on 64-bit) will be inlined automatically (demo only, use `into` for literals as above)
let inline_str = "inlined".to_flex_str();
assert!(inline_str.is_inlined());

// When a string can't be wrapped or inlined, it wil fall back to heap allocation
let rc_str = "This is too long to be inlined. It will be wrapped in `Rc`".to_flex_str();
assert!(rc_str.is_heap());

// You can efficiently create new FlexStrs without ever creating a `String`
// This is equivalent to stdlib `format!` macro
let inline_str2 = flex_fmt!("in{}", "lined");
assert!(inline_str2.is_inlined());
assert_eq!(inline_str, inline_str2);

// We can even upper/lower strings without ever using `String` - the below doesn't allocate
let inline_str3: FlexStr = "INLINED".to_ascii_lower();
assert!(inline_str3.is_inlined());
assert_eq!(inline_str, inline_str3);

// Clone is almost free, even when borrowed (at most it is a ref count increment for heap allocated strings)
let static_str2 = (&static_str).clone();
assert!(static_str2.is_static());

// Regardless of storage type, these all operate seamlessly together and choose storage as required
let heap_str2 = static_str2 + &inline_str;
assert!(heap_str2.is_heap());
assert_eq!(heap_str2, "This will not allocate or copyinlined");  

Macros

AFlexStr equivalent to format! macro from stdlib. Efficiently creates a native AFlexStr

FlexStr equivalent to format! macro from stdlib. Efficiently creates a native FlexStr

Structs

A flexible string type that transparently wraps a string literal, inline string, or an Rc<str>

Traits

A trait that converts the source to a AFlexStr while consuming the original

A trait that converts the source to a FlexStr<T> while consuming the original

A trait that converts the source to a FlexStr while consuming the original

A trait that converts the source to an AFlexStr without consuming it

Trait that provides uppercase/lowercase conversion functions for FlexStr

A trait that converts the source to a FlexStr<T> without consuming it

A trait that converts the source to a FlexStr without consuming it

Functions

FlexStr equivalent to format function from stdlib. Efficiently creates a native FlexStr

Type Definitions

A flexible string type that transparently wraps a string literal, inline string, or an Arc<str>