pub struct StaticNonNulString<const CAP: usize> { /* private fields */ }
Expand description
A UTF-8-encoded string, backed by an array of constant capacity. Can’t contain nul chars.
Internally, the first 0 byte in the array indicates the end of the string.
Implementations§
Source§impl<const CAP: usize> StaticNonNulString<CAP>
impl<const CAP: usize> StaticNonNulString<CAP>
Sourcepub const fn from_char7(c: Char7) -> Self
pub const fn from_char7(c: Char7) -> Self
Sourcepub const fn from_char8(c: Char8) -> Self
pub const fn from_char8(c: Char8) -> Self
Creates a new StaticU8String
from a Char8
.
If c
.is_nul()
an empty string will be returned.
§Panic
Panics if !c.is_nul()
and CAP
< c.
len_utf8()
.
Will never panic if CAP
>= 2.
Sourcepub const fn from_char16(c: Char16) -> Self
pub const fn from_char16(c: Char16) -> Self
Creates a new StaticU8String
from a Char16
.
If c
.is_nul()
an empty string will be returned.
§Panic
Panics if !c.is_nul()
and CAP
< c.
len_utf8()
.
Will never panic if CAP
>= 3.
Sourcepub const fn from_char24(c: Char24) -> Self
pub const fn from_char24(c: Char24) -> Self
Creates a new StaticU8String
from a Char24
.
If c
.is_nul()
an empty string will be returned.
§Panic
Panics if !c.is_nul()
and CAP
< c.
len_utf8()
.
Will never panic if CAP
>= 4.
Sourcepub const fn from_char32(c: Char32) -> Self
pub const fn from_char32(c: Char32) -> Self
Creates a new StaticU8String
from a Char32
.
If c
.is_nul()
an empty string will be returned.
§Panic
Panics if !c.is_nul()
and CAP
< c.
len_utf8()
.
Will never panic if CAP
is >= 4.
Sourcepub const fn from_char(c: char) -> Self
pub const fn from_char(c: char) -> Self
Creates a new StaticU8String
from a char
.
If c
.is_nul()
an empty string will be returned.
§Panic
Panics if !c.is_nul()
and CAP
< c.
len_utf8()
.
Will never panic if CAP
is >= 4.
Sourcepub fn remaining_capacity(&self) -> usize
pub fn remaining_capacity(&self) -> usize
Returns the remaining capacity.
Sourcepub unsafe fn as_bytes_mut(&mut self) -> &mut [u8] ⓘ
Available on crate feature unsafe
only.
pub unsafe fn as_bytes_mut(&mut self) -> &mut [u8] ⓘ
unsafe
only.Returns a mutable byte slice of the inner string slice.
Sourcepub const fn as_array(&self) -> [u8; CAP]
pub const fn as_array(&self) -> [u8; CAP]
Returns a copy of the inner array with the full contents.
The array contains all the bytes, including those outside the current length.
Sourcepub const fn into_array(self) -> [u8; CAP]
pub const fn into_array(self) -> [u8; CAP]
Returns the inner array with the full contents.
The array contains all the bytes, including those outside the current length.
Sourcepub unsafe fn as_str_mut(&mut self) -> &mut str
Available on crate feature unsafe
only.
pub unsafe fn as_str_mut(&mut self) -> &mut str
unsafe
only.Returns the mutable inner string slice.
Sourcepub fn chars(&self) -> Chars<'_>
Available on crate feature alloc
only.
pub fn chars(&self) -> Chars<'_>
alloc
only.Returns an iterator over the chars
of this grapheme cluster.
Sourcepub fn to_cstring(&self) -> CString
Available on crate feature alloc
only.
pub fn to_cstring(&self) -> CString
alloc
only.Returns a new allocated C-compatible, nul-terminanted string.
Sourcepub fn pop(&mut self) -> Option<char>
pub fn pop(&mut self) -> Option<char>
Removes the last character and returns it, or None
if
the string is empty.
Sourcepub fn pop_unchecked(&mut self) -> char
pub fn pop_unchecked(&mut self) -> char
Sourcepub fn push(&mut self, character: char) -> usize
pub fn push(&mut self, character: char) -> usize
Appends to the end of the string the given character
.
Returns the number of bytes written.
It will return 0 bytes if the given character
doesn’t fit in
the remaining capacity, or if it is the nul character.
Sourcepub fn try_push(&mut self, character: char) -> Result<usize>
pub fn try_push(&mut self, character: char) -> Result<usize>
Tries to append to the end of the string the given character
.
Returns the number of bytes written.
Trying to push a nul character does nothing and returns 0 bytes.
§Errors
Returns an error if the capacity is not enough to hold the given character.
Sourcepub fn push_str(&mut self, string: &str) -> usize
pub fn push_str(&mut self, string: &str) -> usize
Appends to the end the fitting characters from the given string
slice.
Nul characters will be stripped out.
Returns the number of bytes written, which will be 0 if not even the first non-nul character can fit.
Sourcepub fn try_push_str(&mut self, string: &str) -> Result<usize>
pub fn try_push_str(&mut self, string: &str) -> Result<usize>
Tries to append to the end the fitting characters from the given string
slice.
Nul characters will be stripped out.
Returns the number of bytes written.
§Errors
Returns an error if the capacity is not enough to hold even the first non-nul character.
Trait Implementations§
Source§impl<const CAP: usize> Clone for StaticNonNulString<CAP>
impl<const CAP: usize> Clone for StaticNonNulString<CAP>
Source§fn clone(&self) -> StaticNonNulString<CAP>
fn clone(&self) -> StaticNonNulString<CAP>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more