pub struct LBString(/* private fields */);Expand description
A Unicode string stored using the Linked Bytes format.
This is more compact than all of the current UTF formats (namely, UTF-1, 7, 8, 16, let alone 32), since no surrogate pairs are used. Instead, the Linked Bytes format is leveraged, with separate codepoints being stored as individual Linked Bytes numbers. Both the link/end bits of the bytes and length of the entire message, either via the null terminator (which still works since a linking 0 has the most significant bit set to 1 and cannot be confused with the null terminator when reinterpreted as u8) or via storing it separately (as Rust Strings do), are available. This means that the UTF-32 number of each codepoint can be encoded using the usual Linked Bytes format, with the link bit cleared in a byte indicating that one character has ended and a new one is coming next.
§Usage
Conversion from String or &str:
static MY_STRING: &str = "My string!";
let stdstring = String::from("This is a standard string!");
let my_string_lb = LBString::from(MY_STRING); // Creates an LBString from a string slice
let stdstring_lb = LBString::from(stdstring); // Creates an LBString from a String
let my_string_lb_2 = MY_STRING.chars().collect::<LBString>(); // Creates an LBString from an iterator
Implementations§
Source§impl LBString
impl LBString
Sourcepub fn chars(&self) -> impl Iterator<Item = char> + '_
pub fn chars(&self) -> impl Iterator<Item = char> + '_
Returns an iterator over the codepoints in the string.
This is the core method of this type. Most other methods use this to perform more complex operations, such as conversion from an &str.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Counts the number of codepoints stored.
This will iterate through the entire string and count how many codepoints were resolved successfully. Currently, this is implemented as simply self.chars().count().
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if there are no codepoints stored, false otherwise.
Sourcepub const fn inner(&self) -> &LBSequence
pub const fn inner(&self) -> &LBSequence
Returns an immutable reference to the underlying sequence.
Trait Implementations§
Source§impl<'a> FromIterator<&'a char> for LBString
impl<'a> FromIterator<&'a char> for LBString
Source§fn from_iter<I: IntoIterator<Item = &'a char>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = &'a char>>(iter: I) -> Self
Convenience implementation for collections which iterate over references to items rather than the items themselves, to avoid repetitive .copied() in calling code.