pub struct ConstString<const N: usize>(/* private fields */);
Expand description
A string with a fixed-capacity array as storage to be used in compile-time constants.
Causes an unfriendly compile-time error when the size of the string exceeds its capacity.
This struct always upholds that it contains valid utf-8.
Implementations§
Source§impl<const N: usize> ConstString<N>
impl<const N: usize> ConstString<N>
Sourcepub const unsafe fn from_bytes(slice: &[u8]) -> Self
pub const unsafe fn from_bytes(slice: &[u8]) -> Self
Creates a new ConstString
from a slice of bytes.
Will return [ConstString::ErrTooLong
] if the array is longer than the capacity of the ConstString
.
§Safety
The slice must contain valid utf-8.
§Panics
If the length of the slice exceeds the capacity of the array.
Sourcepub const fn from_str(string: &str) -> Self
pub const fn from_str(string: &str) -> Self
Creates a new ConstString
from a &str
.
§Panics
If the length of the string exceeds the capacity of the array.
Sourcepub const unsafe fn with_bytes(self, other: &[u8]) -> Self
pub const unsafe fn with_bytes(self, other: &[u8]) -> Self
Extends the array in a ConstString
by value with a slice of bytes.
§Safety
The slice must contain valid utf-8.
§Panics
If the length of the string exceeds the remaining space in the array.
Sourcepub const fn with_str(self, other: &str) -> Self
pub const fn with_str(self, other: &str) -> Self
Extends the array in a ConstString
by value with a string slice.
Sourcepub const fn with<const M: usize>(self, other: ConstString<M>) -> Self
pub const fn with<const M: usize>(self, other: ConstString<M>) -> Self
Extends the array in a ConstString
by value with another ConstString
.
Sourcepub const fn as_str(&self) -> &str
pub const fn as_str(&self) -> &str
Returns the string in this ConstString
as an &str
Trait Implementations§
Source§impl<const N: usize> Clone for ConstString<N>
impl<const N: usize> Clone for ConstString<N>
Source§fn clone(&self) -> ConstString<N>
fn clone(&self) -> ConstString<N>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more