Struct flipperzero::furi::string::FuriString
source · 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
impl FuriString
sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a new empty FuriString
with at least the specified capacity.
sourcepub fn as_c_str(&self) -> &CStr
pub fn as_c_str(&self) -> &CStr
Extracts a CStr
containing the entire string slice, with nul termination.
sourcepub fn push_string(&mut self, string: &FuriString)
pub fn push_string(&mut self, string: &FuriString)
Appends a given FuriString
onto the end of this FuriString
.
sourcepub fn push_c_str(&mut self, string: &CStr)
pub fn push_c_str(&mut self, string: &CStr)
Appends a given CStr
onto the end of this FuriString
.
sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserves capacity for at least additional
bytes more than the current length.
sourcepub fn to_bytes(&self) -> &[u8]
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.
sourcepub fn to_bytes_with_nul(&self) -> &[u8]
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.
sourcepub fn truncate(&mut self, new_len: usize)
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.
sourcepub fn insert(&mut self, idx: usize, ch: char)
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.
sourcepub fn insert_str(&mut self, idx: usize, string: &str)
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.
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the length of this FuriString
.
This length is in bytes, not char
s or graphemes. In other words, it might not
be what a human considers the length of the string.
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true
if this FuriString
has a length of zero, and false
otherwise.
sourcepub fn split_off(&mut self, at: usize) -> FuriString
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§impl FuriString
impl FuriString
sourcepub fn chars_lossy(&self) -> Chars<'_>
pub fn chars_lossy(&self) -> Chars<'_>
Returns an iterator over the char
s 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.
sourcepub fn char_indices_lossy(&self) -> CharIndices<'_>
pub fn char_indices_lossy(&self) -> CharIndices<'_>
Returns an iterator over the char
s 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.
sourcepub fn bytes(&self) -> Bytes<'_>
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.
sourcepub fn starts_with<P: Pattern>(&self, pat: P) -> bool
pub fn starts_with<P: Pattern>(&self, pat: P) -> bool
sourcepub fn trim(&mut self)
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.
sourcepub fn trim_start(&mut self)
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.
sourcepub fn trim_end(&mut self)
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.
sourcepub fn trim_matches<P: Pattern + Copy>(&mut self, pat: P)
pub fn trim_matches<P: Pattern + Copy>(&mut self, pat: P)
sourcepub fn trim_start_matches<P: Pattern + Copy>(&mut self, pat: P)
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
char
s.
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.
sourcepub fn trim_end_matches<P: Pattern + Copy>(&mut self, pat: P)
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
char
s.
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.
sourcepub fn strip_prefix<P: Pattern>(&mut self, prefix: P) -> bool
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
char
s.
sourcepub fn strip_suffix<P: Pattern>(&mut self, suffix: P) -> bool
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
char
s.
Trait Implementations§
source§impl Add<&str> for FuriString
impl Add<&str> for FuriString
source§impl AddAssign<&str> for FuriString
impl AddAssign<&str> for FuriString
source§fn add_assign(&mut self, rhs: &str)
fn add_assign(&mut self, rhs: &str)
+=
operation. Read moresource§impl AsRef<CStr> for FuriString
impl AsRef<CStr> for FuriString
source§impl Borrow<CStr> for FuriString
impl Borrow<CStr> for FuriString
source§impl Clone for FuriString
impl Clone for FuriString
source§impl Debug for FuriString
impl Debug for FuriString
source§impl Default for FuriString
impl Default for FuriString
source§impl Display for FuriString
impl Display for FuriString
source§impl Drop for FuriString
impl Drop for FuriString
source§impl<'a> Extend<&'a CStr> for FuriString
impl<'a> Extend<&'a CStr> for FuriString
source§fn extend<T: IntoIterator<Item = &'a CStr>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = &'a CStr>>(&mut self, iter: T)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl<'a> Extend<&'a char> for FuriString
impl<'a> Extend<&'a char> for FuriString
source§fn extend<T: IntoIterator<Item = &'a char>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = &'a char>>(&mut self, iter: T)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl<'a> Extend<&'a str> for FuriString
impl<'a> Extend<&'a str> for FuriString
source§fn extend<T: IntoIterator<Item = &'a str>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = &'a str>>(&mut self, iter: T)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl Extend<Box<str, Global>> for FuriString
impl Extend<Box<str, Global>> for FuriString
source§fn extend<T: IntoIterator<Item = Box<str>>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = Box<str>>>(&mut self, iter: T)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl<'a> Extend<Cow<'a, str>> for FuriString
impl<'a> Extend<Cow<'a, str>> for FuriString
source§fn extend<T: IntoIterator<Item = Cow<'a, str>>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = Cow<'a, str>>>(&mut self, iter: T)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl Extend<FuriString> for FuriString
impl Extend<FuriString> for FuriString
source§fn extend<T: IntoIterator<Item = FuriString>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = FuriString>>(&mut self, iter: T)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl Extend<char> for FuriString
impl Extend<char> for FuriString
source§fn extend<T: IntoIterator<Item = char>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = char>>(&mut self, iter: T)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl From<&CStr> for FuriString
impl From<&CStr> for FuriString
source§impl From<&mut str> for FuriString
impl From<&mut str> for FuriString
source§impl From<&str> for FuriString
impl From<&str> for FuriString
source§impl From<char> for FuriString
impl From<char> for FuriString
source§impl<'a> FromIterator<&'a CStr> for FuriString
impl<'a> FromIterator<&'a CStr> for FuriString
source§impl<'a> FromIterator<&'a char> for FuriString
impl<'a> FromIterator<&'a char> for FuriString
source§impl<'a> FromIterator<&'a str> for FuriString
impl<'a> FromIterator<&'a str> for FuriString
source§impl FromIterator<Box<str, Global>> for FuriString
impl FromIterator<Box<str, Global>> for FuriString
source§impl<'a> FromIterator<Cow<'a, str>> for FuriString
impl<'a> FromIterator<Cow<'a, str>> for FuriString
source§impl FromIterator<FuriString> for FuriString
impl FromIterator<FuriString> for FuriString
source§fn from_iter<T: IntoIterator<Item = FuriString>>(iter: T) -> Self
fn from_iter<T: IntoIterator<Item = FuriString>>(iter: T) -> Self
source§impl FromIterator<char> for FuriString
impl FromIterator<char> for FuriString
source§impl Hash for FuriString
impl Hash for FuriString
source§impl Ord for FuriString
impl Ord for FuriString
source§impl PartialEq<&str> for FuriString
impl PartialEq<&str> for FuriString
source§impl PartialEq<CStr> for FuriString
impl PartialEq<CStr> for FuriString
source§impl PartialEq<CString> for FuriString
impl PartialEq<CString> for FuriString
source§impl PartialEq<FuriString> for &str
impl PartialEq<FuriString> for &str
source§fn eq(&self, other: &FuriString) -> bool
fn eq(&self, other: &FuriString) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialEq<FuriString> for CStr
impl PartialEq<FuriString> for CStr
source§fn eq(&self, other: &FuriString) -> bool
fn eq(&self, other: &FuriString) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialEq<FuriString> for CString
impl PartialEq<FuriString> for CString
source§fn eq(&self, other: &FuriString) -> bool
fn eq(&self, other: &FuriString) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialEq<FuriString> for FuriString
impl PartialEq<FuriString> for FuriString
source§impl PartialEq<FuriString> for str
impl PartialEq<FuriString> for str
source§fn eq(&self, other: &FuriString) -> bool
fn eq(&self, other: &FuriString) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialEq<str> for FuriString
impl PartialEq<str> for FuriString
source§impl PartialOrd<FuriString> for FuriString
impl PartialOrd<FuriString> for FuriString
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more