pub struct FixedStr<const N: usize, Alignment> { /* private fields */ }Expand description
Fixed stack-allocated string
The characters are stored within FixedStr’s internal buffer. It is suitable for any fixed-length data having a valid UTF-8 representation. Common uses for FixedStr include identifiers and hashes.
Unlike BoundedStr, the length is not encoded and is assumed to match the
capacity N. However, if the string is shorter than N, the remaining
bytes will be NUL-padded.
§Aliases
Implementations§
Source§impl<const N: usize, Alignment> FixedStr<N, Alignment>
impl<const N: usize, Alignment> FixedStr<N, Alignment>
Sourcepub const unsafe fn from_bytes(data: [u8; N]) -> Self
pub const unsafe fn from_bytes(data: [u8; N]) -> Self
§Safety
This function requires that the provided bytes can be represented by a UTF-8 string. Otherwise, Self::as_str and Self::as_str_trimmed are not well-defined.
Sourcepub fn try_from(s: &str) -> Result<Self, ExceedsCapacity>
pub fn try_from(s: &str) -> Result<Self, ExceedsCapacity>
It is possible to construct a FixedStr shorter than its capacity, in which case the missing bytes will be filled with NULs.
Sourcepub const fn const_from(s: &str) -> Self
pub const fn const_from(s: &str) -> Self
Builds FixedStr within a const context
Sourcepub const fn const_try_from(s: &str) -> Option<Self>
pub const fn const_try_from(s: &str) -> Option<Self>
Attempts to build FixedStr within a const context
Sourcepub fn as_str_trimmed(&self) -> &str
pub fn as_str_trimmed(&self) -> &str
Converts FixedStr to a &str. If the value is NUL-padded or contains NULs, this stops at the first NUL byte.
Sourcepub fn to_string_trimmed(&self) -> String
pub fn to_string_trimmed(&self) -> String
Converts FixedStr to a String. If the value is NUL-padded or contains NULs, this stops at the first NUL byte.
Trait Implementations§
Source§impl<'de, const N: usize, Alignment> Deserialize<'de> for FixedStr<N, Alignment>
Available on crate feature serde only.
impl<'de, const N: usize, Alignment> Deserialize<'de> for FixedStr<N, Alignment>
serde only.Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl<const N: usize, Alignment> From<&String> for FixedStr<N, Alignment>
Available on crate feature std only.
impl<const N: usize, Alignment> From<&String> for FixedStr<N, Alignment>
std only.Source§impl<const N: usize, Alignment> From<String> for FixedStr<N, Alignment>
Available on crate feature std only.
impl<const N: usize, Alignment> From<String> for FixedStr<N, Alignment>
std only.Source§impl<const N: usize, Alignment: Ord> Ord for FixedStr<N, Alignment>
impl<const N: usize, Alignment: Ord> Ord for FixedStr<N, Alignment>
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<const N: usize, Alignment: PartialOrd> PartialOrd for FixedStr<N, Alignment>
impl<const N: usize, Alignment: PartialOrd> PartialOrd for FixedStr<N, Alignment>
Source§impl<const N: usize, Alignment> Serialize for FixedStr<N, Alignment>
Available on crate feature serde only.
impl<const N: usize, Alignment> Serialize for FixedStr<N, Alignment>
serde only.