pub struct FuriString(_);
Expand description

A Furi string.

This is similar to Rust’s CString in that it represents an owned, C-compatible, nul-terminated string with no nul bytes in the middle. It also has additional methods to provide the flexibility of Rust’s String. It is used in various APIs of the Flipper Zero SDK.

This type does not require the alloc feature flag, because it does not use the Rust allocator. Very short strings (7 bytes or fewer) are stored directly inside the FuriString struct (which is stored on the heap), while longer strings are allocated on the heap by the Flipper Zero firmware.

Implementations§

source§

impl FuriString

source

pub fn new() -> Self

Creates a new empty FuriString.

source

pub fn with_capacity(capacity: usize) -> Self

Creates a new empty FuriString with at least the specified capacity.

source

pub fn as_c_str(&self) -> &CStr

Extracts a CStr containing the entire string slice, with nul termination.

source

pub fn push_string(&mut self, string: &FuriString)

Appends a given FuriString onto the end of this FuriString.

source

pub fn push_str(&mut self, string: &str)

Appends a given str onto the end of this FuriString.

source

pub fn push_c_str(&mut self, string: &CStr)

Appends a given CStr onto the end of this FuriString.

source

pub fn reserve(&mut self, additional: usize)

Reserves capacity for at least additional bytes more than the current length.

source

pub fn push(&mut self, ch: char)

Appends the given char to the end of this FuriString.

source

pub fn to_bytes(&self) -> &[u8]

Returns a byte slice of this FuriString’s contents.

The returned slice will not contain the trailing nul terminator that the underlying C string has.

source

pub fn to_bytes_with_nul(&self) -> &[u8]

Returns a byte slice of this FuriString’s contents with the trailing nul byte.

This function is the equivalent of FuriString::to_bytes except that it will retain the trailing nul terminator instead of chopping it off.

source

pub fn truncate(&mut self, new_len: usize)

Shortens this FuriString to the specified length.

If new_len is greater than the string’s current length, this has no effect.

source

pub fn insert(&mut self, idx: usize, ch: char)

Inserts a character into this FuriString at a byte position.

This is an O(n) operation as it requires copying every element in the buffer.

Panics

Panics if idx is larger than the FuriString’s length.

source

pub fn insert_str(&mut self, idx: usize, string: &str)

Inserts a string slice into this FuriString at a byte position.

This is an O(n) operation as it requires copying every element in the buffer.

Panics

Panics if idx is larger than the FuriString’s length.

source

pub fn len(&self) -> usize

Returns the length of this FuriString.

This length is in bytes, not chars or graphemes. In other words, it might not be what a human considers the length of the string.

source

pub fn is_empty(&self) -> bool

Returns true if this FuriString has a length of zero, and false otherwise.

source

pub fn split_off(&mut self, at: usize) -> FuriString

Splits the string into two at the given byte index.

Returns a newly allocated String. self contains bytes [0, at), and the returned String contains bytes [at, len).

Note that the capacity of self does not change.

Panics

Panics if at is beyond the last byte of the string.

source

pub fn clear(&mut self)

Truncates this FuriString, removing all contents.

While this means the FuriString will have a length of zero, it does not touch its capacity.

source§

impl FuriString

source

pub fn chars_lossy(&self) -> Chars<'_>

Returns an iterator over the chars of a FuriString.

A FuriString might not contain valid UTF-8 (for example, if it represents a string obtained through the Flipper Zero SDK).Any invalid UTF-8 sequences will be replaced with U+FFFD REPLACEMENT CHARACTER, which looks like this: �

It’s important to remember that char represents a Unicode Scalar Value, and might not match your idea of what a ‘character’ is. Iteration over grapheme clusters may be what you actually want.

source

pub fn char_indices_lossy(&self) -> CharIndices<'_>

Returns an iterator over the chars of a FuriString, and their positions.

A FuriString might not contain valid UTF-8 (for example, if it represents a string obtained through the Flipper Zero SDK).Any invalid UTF-8 sequences will be replaced with U+FFFD REPLACEMENT CHARACTER, which looks like this: �

The iterator yields tuples. The position is first, the char is second.

source

pub fn bytes(&self) -> Bytes<'_>

An iterator over the bytes of a string slice.

As a string consists of a sequence of bytes, we can iterate through a string by byte. This method returns such an iterator.

source

pub fn contains<P: Pattern>(&self, pat: P) -> bool

Returns true if the given pattern pat matches a sub-slice of this string slice.

Returns false if it does not.

The pattern can be a &FuriString, c_char, &CStr, char, or a slice of chars.

source

pub fn starts_with<P: Pattern>(&self, pat: P) -> bool

Returns true if the given pattern pat matches a prefix of this string slice.

Returns false if it does not.

The pattern can be a &FuriString, c_char, &CStr, char, or a slice of chars.

source

pub fn ends_with<P: Pattern>(&self, pat: P) -> bool

Returns true if the given pattern pat matches a suffix of this string slice.

Returns false if it does not.

The pattern can be a &FuriString, c_char, &CStr, char, or a slice of chars.

source

pub fn find<P: Pattern>(&self, pat: P) -> Option<usize>

Returns the byte index of the first byte of this string that matches the pattern pat.

Returns None if the pattern doesn’t match.

The pattern can be a &FuriString, c_char, &CStr, char, or a slice of chars.

source

pub fn rfind<P: Pattern>(&self, pat: P) -> Option<usize>

Returns the byte index for the first byte of the last match of the pattern pat in this string.

Returns None if the pattern doesn’t match.

The pattern can be a &FuriString, c_char, &CStr, char, or a slice of chars.

source

pub fn trim(&mut self)

Removes leading and trailing whitespace from this string.

‘Whitespace’ is defined according to the terms of the Unicode Derived Core Property White_Space, which includes newlines.

source

pub fn trim_start(&mut self)

Removes leading whitespace from this string.

‘Whitespace’ is defined according to the terms of the Unicode Derived Core Property White_Space, which includes newlines.

Text directionality

A string is a sequence of bytes. start in this context means the first position of that byte string; for a left-to-right language like English or Russian, this will be left side, and for right-to-left languages like Arabic or Hebrew, this will be the right side.

source

pub fn trim_end(&mut self)

Removes trailing whitespace from this string.

‘Whitespace’ is defined according to the terms of the Unicode Derived Core Property White_Space, which includes newlines.

Text directionality

A string is a sequence of bytes. end in this context means the last position of that byte string; for a left-to-right language like English or Russian, this will be right side, and for right-to-left languages like Arabic or Hebrew, this will be the left side.

source

pub fn trim_matches<P: Pattern + Copy>(&mut self, pat: P)

Repeatedly removes from this string all prefixes and suffixes that match a pattern.

The pattern can be a &FuriString, c_char, &CStr, char, or a slice of chars.

source

pub fn trim_start_matches<P: Pattern + Copy>(&mut self, pat: P)

Repeatedly removes from this string all prefixes that match a pattern pat.

The pattern can be a &FuriString, c_char, &CStr, char, or a slice of chars.

Text directionality

A string is a sequence of bytes. start in this context means the first position of that byte string; for a left-to-right language like English or Russian, this will be left side, and for right-to-left languages like Arabic or Hebrew, this will be the right side.

source

pub fn trim_end_matches<P: Pattern + Copy>(&mut self, pat: P)

Repeatedly removes from this string all suffixes that match a pattern pat.

The pattern can be a &FuriString, c_char, &CStr, char, or a slice of chars.

Text directionality

A string is a sequence of bytes. end in this context means the last position of that byte string; for a left-to-right language like English or Russian, this will be right side, and for right-to-left languages like Arabic or Hebrew, this will be the left side.

source

pub fn strip_prefix<P: Pattern>(&mut self, prefix: P) -> bool

Removes the given prefix from this string.

If the string starts with the pattern prefix, returns true. Unlike Self::trim_start_matches, this method removes the prefix exactly once.

If the string does not start with prefix, returns false.

The prefix can be a &FuriString, c_char, &CStr, char, or a slice of chars.

source

pub fn strip_suffix<P: Pattern>(&mut self, suffix: P) -> bool

Removes the given suffix from this string.

If the string ends with the pattern suffix, returns true. Unlike Self::trim_end_matches, this method removes the suffix exactly once.

If the string does not end with suffix, returns false.

The suffix can be a &FuriString, c_char, &CStr, char, or a slice of chars.

Trait Implementations§

source§

impl Add<&str> for FuriString

§

type Output = FuriString

The resulting type after applying the + operator.
source§

fn add(self, rhs: &str) -> Self::Output

Performs the + operation. Read more
source§

impl AddAssign<&str> for FuriString

source§

fn add_assign(&mut self, rhs: &str)

Performs the += operation. Read more
source§

impl AsRef<CStr> for FuriString

source§

fn as_ref(&self) -> &CStr

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Borrow<CStr> for FuriString

source§

fn borrow(&self) -> &CStr

Immutably borrows from an owned value. Read more
source§

impl Clone for FuriString

source§

fn clone(&self) -> Self

Returns a copy 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 FuriString

source§

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

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

impl Default for FuriString

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Display for FuriString

source§

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

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

impl Drop for FuriString

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<'a> Extend<&'a CStr> for FuriString

source§

fn extend<T: IntoIterator<Item = &'a CStr>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl<'a> Extend<&'a char> for FuriString

source§

fn extend<T: IntoIterator<Item = &'a char>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl<'a> Extend<&'a str> for FuriString

source§

fn extend<T: IntoIterator<Item = &'a str>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl Extend<Box<str, Global>> for FuriString

source§

fn extend<T: IntoIterator<Item = Box<str>>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl<'a> Extend<Cow<'a, str>> for FuriString

source§

fn extend<T: IntoIterator<Item = Cow<'a, str>>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl Extend<FuriString> for FuriString

source§

fn extend<T: IntoIterator<Item = FuriString>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl Extend<char> for FuriString

source§

fn extend<T: IntoIterator<Item = char>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl From<&CStr> for FuriString

source§

fn from(value: &CStr) -> Self

Converts to this type from the input type.
source§

impl From<&mut str> for FuriString

source§

fn from(value: &mut str) -> Self

Converts to this type from the input type.
source§

impl From<&str> for FuriString

source§

fn from(value: &str) -> Self

Converts to this type from the input type.
source§

impl From<Box<str, Global>> for FuriString

source§

fn from(value: Box<str>) -> Self

Converts to this type from the input type.
source§

impl<'a> From<Cow<'a, str>> for FuriString

source§

fn from(value: Cow<'a, str>) -> Self

Converts to this type from the input type.
source§

impl From<char> for FuriString

source§

fn from(value: char) -> Self

Converts to this type from the input type.
source§

impl<'a> FromIterator<&'a CStr> for FuriString

source§

fn from_iter<T: IntoIterator<Item = &'a CStr>>(iter: T) -> Self

Creates a value from an iterator. Read more
source§

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

source§

fn from_iter<T: IntoIterator<Item = &'a char>>(iter: T) -> Self

Creates a value from an iterator. Read more
source§

impl<'a> FromIterator<&'a str> for FuriString

source§

fn from_iter<T: IntoIterator<Item = &'a str>>(iter: T) -> Self

Creates a value from an iterator. Read more
source§

impl FromIterator<Box<str, Global>> for FuriString

source§

fn from_iter<T: IntoIterator<Item = Box<str>>>(iter: T) -> Self

Creates a value from an iterator. Read more
source§

impl<'a> FromIterator<Cow<'a, str>> for FuriString

source§

fn from_iter<T: IntoIterator<Item = Cow<'a, str>>>(iter: T) -> Self

Creates a value from an iterator. Read more
source§

impl FromIterator<FuriString> for FuriString

source§

fn from_iter<T: IntoIterator<Item = FuriString>>(iter: T) -> Self

Creates a value from an iterator. Read more
source§

impl FromIterator<char> for FuriString

source§

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

Creates a value from an iterator. Read more
source§

impl Hash for FuriString

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for FuriString

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl PartialEq<&str> for FuriString

source§

fn eq(&self, other: &&str) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<CStr> for FuriString

source§

fn eq(&self, other: &CStr) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<CString> for FuriString

source§

fn eq(&self, other: &CString) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<FuriString> for &str

source§

fn eq(&self, other: &FuriString) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<FuriString> for CStr

source§

fn eq(&self, other: &FuriString) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<FuriString> for CString

source§

fn eq(&self, other: &FuriString) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<FuriString> for FuriString

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<FuriString> for str

source§

fn eq(&self, other: &FuriString) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<str> for FuriString

source§

fn eq(&self, other: &str) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<FuriString> for FuriString

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Write for FuriString

source§

fn write_str(&mut self, s: &str) -> Result

Writes a string slice into this writer, returning whether the write succeeded. Read more
source§

fn write_char(&mut self, c: char) -> Result

Writes a char into this writer, returning whether the write succeeded. Read more
1.0.0 · source§

fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error>

Glue for usage of the write! macro with implementors of this trait. Read more
source§

impl uDebug for FuriString

source§

fn fmt<W>(&self, f: &mut Formatter<'_, W>) -> Result<(), W::Error>where W: uWrite + ?Sized,

Formats the value using the given formatter
source§

impl uDisplay for FuriString

source§

fn fmt<W>(&self, f: &mut Formatter<'_, W>) -> Result<(), W::Error>where W: uWrite + ?Sized,

Formats the value using the given formatter
source§

impl uWrite for FuriString

§

type Error = Infallible

The error associated to this writer
source§

fn write_str(&mut self, s: &str) -> Result<(), Self::Error>

Writes a string slice into this writer, returning whether the write succeeded. Read more
source§

fn write_char(&mut self, c: char) -> Result<(), Self::Error>

Writes a char into this writer, returning whether the write succeeded. Read more
source§

impl Eq for FuriString

source§

impl StructuralEq for FuriString

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

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

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

§

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 Twhere U: TryFrom<T>,

§

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.