Skip to main content

Module fixed_string

Module fixed_string 

Source
Expand description

Fixed-length string type for shared memory variables. Fixed-length string type for shared memory variables.

FixedString<N> is a Copy-able, repr(transparent) wrapper around [u8; N] that stores UTF-8 text zero-padded to a fixed capacity. It is designed for use in #[repr(C)] structs that are shared via memory-mapped regions between processes.

§Example

use autocore_std::FixedString;

let mut s = FixedString::<64>::new();
assert!(s.is_empty());

s.set("Hello, world!");
assert_eq!(s.as_str(), "Hello, world!");
assert_eq!(s.len(), 13);

// Strings longer than N are silently truncated at a UTF-8 boundary
let mut tiny = FixedString::<4>::new();
tiny.set("Hello");
assert_eq!(tiny.as_str(), "Hell");

Structs§

FixedString
A fixed-capacity string stored as a zero-padded UTF-8 byte array.