Struct LBString

Source
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

Source

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.

Source

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().

Source

pub fn is_empty(&self) -> bool

Returns true if there are no codepoints stored, false otherwise.

Source

pub const fn inner(&self) -> &LBSequence

Returns an immutable reference to the underlying sequence.

Trait Implementations§

Source§

impl Clone for LBString

Source§

fn clone(&self) -> LBString

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LBString

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for LBString

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> FromIterator<&'a char> for LBString

Source§

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.

Source§

impl FromIterator<char> for LBString

Source§

fn from_iter<I: IntoIterator<Item = char>>(iter: I) -> Self

Creates a value from an iterator. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.