#[repr(C)]pub struct Str<const N: usize> { /* private fields */ }Expand description
A fixed sized stack string
Str is a generic stack-based string with a maximum byte length of u8::MAX.
The generic N is a usize and represents the maximum length of the string,
however all constructor functions for Str will panic at compile time if N > 255.
Size
The internal length is stored as a u8, and as such will
take minimal space, allowing for longer strings to be stored.
Due to #[repr(C)], N + 1 is how many bytes your Str will take up.
Using Str in powers of 2 is recommended.
// 64 bytes in total, 63 bytes available for the string.
// This will fit in a typical CPU cache-line.
assert_eq!(std::mem::size_of::<Str::<63>>(), 64);
// Maximum string length of 255 fits into 256 bytes.
assert_eq!(std::mem::size_of::<Str::<255>>(), 256);
// Beware, due to `#[repr(C)]`, `Str` is not
// automatically re-arranged and padded by Rust.
assert_eq!(std::mem::size_of::<Str::<6>>(), 7);Compile-time panic
Any usage of Str will panic at compile time if N > 255:
/// These will all panic at _compile time_
Str::<256>::new();
Str::<256>::try_from("");
Str::<256>::from_static_str("");
Str::<256>::from_static_bytes(b"");Usage
// Create a `Str` with a maximum capacity of `24` bytes.
const N: usize = 24;
let mut string = Str::<N>::new();
assert!(string.is_empty());
// Copy the bytes from an actual `str`
let other_str = "this str is 24 bytes :-)";
assert_eq!(other_str.len(), N);
string.copy_str(other_str).unwrap();
// They're the same.
assert_eq!(string, other_str);
// Clear the string.
string.clear();
assert!(string.is_empty());
assert_eq!(string.len(), 0);
// `push_str()` should be the exact same.
string.push_str(other_str).unwrap();
assert_eq!(string, other_str);
// This string is full.
assert!(string.is_full());
assert_eq!(string.len(), N);
// Pushing new strings will error.
let err = string.push_str(other_str);
assert_eq!(err, Err(24));
// Still the same.
assert_eq!(string, other_str);
// Although, we can still overwrite it.
string.copy_str("hello-------------------");
assert_eq!(string, "hello-------------------");
assert_eq!(string.len(), 24);Implementations§
source§impl<const N: usize> Str<N>
impl<const N: usize> Str<N>
sourcepub const CAPACITY: u8 = _
pub const CAPACITY: u8 = _
The maximum length of this string as a u8.
This should == to N in valid cases.
Compile-time panic
This associated constant will cause Str constructor
functions to panic at compile time is N > 255.
sourcepub const fn new() -> Self
pub const fn new() -> Self
Returns an empty Str.
let string = Str::<4>::new();
assert!(string.is_empty());
assert_eq!(string.len(), 0);
assert!(string.as_str().is_empty());
assert_eq!(string.as_str().len(), 0);sourcepub const fn from_static_bytes(bytes: &'static [u8]) -> Self
pub const fn from_static_bytes(bytes: &'static [u8]) -> Self
Create a Self from static bytes.
The length of the input doesn’t need to be the
same as N, it just needs to be equal or less.
Exact length:
const BYTES: [u8; 3] = *b"abc";
const STR: Str<3> = Str::from_static_bytes(&BYTES);
assert_eq!(STR, "abc");Slightly less length is okay too:
const BYTES: [u8; 2] = *b"ab";
const STR: Str<3> = Str::from_static_bytes(&BYTES);
assert_eq!(STR.len(), 2);
assert_eq!(STR, "ab");Compile-time panic
This function will panic at compile time if either:
- The
bytelength is longer thanN - The byte’s are not valid UTF-8 bytes
// This doesn't fit, will panic at compile time.
const STR: Str<3> = Str::from_static_bytes("abcd");sourcepub const fn from_static_str(s: &'static str) -> Self
pub const fn from_static_str(s: &'static str) -> Self
Create a Self from a static str.
The length of the input doesn’t need to be the
same as N, it just needs to be equal or less.
Exact length:
const S: &str = "abc";
const STR: Str<3> = Str::from_static_str(&S);
assert_eq!(STR, "abc");Slightly less length is okay too:
const S: &str = "ab";
const STR: Str<3> = Str::from_static_str(&S);
assert_eq!(STR.len(), 2);
assert_eq!(STR, "ab");Compile-time panic
This function will panic at compile time
if the str length is longer than N.
// This doesn't fit, will panic at compile time.
const STR: Str<3> = Str::from_static_str("abcd");sourcepub const fn as_bytes_all(&self) -> &[u8] ⓘ
pub const fn as_bytes_all(&self) -> &[u8] ⓘ
Return all the bytes of this Str, whether valid UTF-8 or not.
let mut string = Str::<10>::new();
string.push_str("hello").unwrap();
// The string length is 5, but the slice
// returned is the full capacity, 10.
assert_eq!(string.as_bytes_all().len(), 10);sourcepub unsafe fn as_bytes_all_mut(&mut self) -> &mut [u8] ⓘ
pub unsafe fn as_bytes_all_mut(&mut self) -> &mut [u8] ⓘ
Return all the bytes of this Str (mutably), whether valid UTF-8 or not
Safety
The caller must ensure that the content of the slice is valid
UTF-8 before the borrow ends and the underlying Str is used.
The caller must also ensure the len is correctly set
with Str::set_len or Str::set_len_u8.
let mut string = Str::<5>::new();
string.push_str("hi").unwrap();
assert_eq!(string, "hi");
assert_eq!(string.len(), 2);
// Safety: We must ensure we leave
// leave the bytes as valid UTF-8 bytes
// and that we set the length correctly.
unsafe {
// Mutate to valid UTF-8 bytes.
let mut_ref = string.as_bytes_all_mut();
mut_ref.copy_from_slice(&b"world"[..]);
// Set the new length.
string.set_len(5);
}
assert_eq!(string, "world");
assert_eq!(string.len(), 5);sourcepub const fn len(&self) -> usize
pub const fn len(&self) -> usize
Return the length of the valid UTF-8 bytes of this Str
let mut s = Str::<5>::new();
s.push_str("h").unwrap();
assert_eq!(s.len(), 1_usize);
s.push_str("ello").unwrap();
assert_eq!(s.len(), 5_usize);sourcepub const fn capacity(&self) -> u8
pub const fn capacity(&self) -> u8
Returns the maximum capacity (Self::CAPACITY) of this Str.
Should be exactly equal to N.
// This is N (usize) This is CAPACITY (u8)
// | / |
// | | |
// v v v
assert_eq!(Str::<10>::CAPACITY, 10_u8);
let s = Str::<10>::new();
assert_eq!(s.capacity(), 10_u8);sourcepub unsafe fn set_len(&mut self, len: usize)
pub unsafe fn set_len(&mut self, len: usize)
Set the length of the valid UTF-8 bytes of this Str
This will usually be used when manually mutating Str with Str::as_bytes_all_mut().
let mut s = Str::<3>::new();
assert_eq!(s.len(), 0);
unsafe { s.set_len(3); } // <- Using the `Str`
assert_eq!(s.len(), 3); // beyond this point
// is a bad idea.
// This wouldn't be undefined behavior,
// but the inner buffer is all zeros.
assert_eq!(s.as_str(), "\0\0\0");
// Overwrite the bytes.
unsafe {
let mut_ref = s.as_bytes_all_mut();
mut_ref[0] = b'a';
mut_ref[1] = b'b';
mut_ref[2] = b'c';
}
// Should be safe from this point.
assert_eq!(s.as_str(), "abc");
assert_eq!(s.len(), 3);Safety
Other functions will rely on the internal length to be correct, so the caller must ensure this length is actually correct.
sourcepub unsafe fn set_len_u8(&mut self, len: u8)
pub unsafe fn set_len_u8(&mut self, len: u8)
Set the length of the valid UTF-8 bytes of this Str
This will usually be used when manually mutating Str with Str::as_bytes_all_mut().
Safety
Other functions will rely on the internal length to be correct, so the caller must ensure this length is actually correct.
sourcepub const fn remaining(&self) -> usize
pub const fn remaining(&self) -> usize
How many available bytes are left in this Str
before the Self::CAPACITY is completely filled.
let mut s = Str::<5>::new();
s.push_str("hi");
assert_eq!(s.remaining(), 3);sourcepub const fn as_bytes(&self) -> &[u8] ⓘ
pub const fn as_bytes(&self) -> &[u8] ⓘ
Returns only the valid UTF-8 bytes of this Str as a byte slice.
let s = Str::<10>::from_static_str("hello");
assert_eq!(s.as_bytes().len(), 5);sourcepub const fn as_ptr(&self) -> *const u8
pub const fn as_ptr(&self) -> *const u8
Returns a pointer to the first byte in the string array.
sourcepub fn into_vec(self) -> Vec<u8>where
Self: Sized,
pub fn into_vec(self) -> Vec<u8>where
Self: Sized,
Returns only the valid UTF-8 bytes of this Str as a Vec<u8>
let s = Str::<10>::from_static_str("hello");
let v = s.into_vec();
assert_eq!(v.len(), 5);
let s = unsafe { String::from_utf8_unchecked(v) };
assert_eq!(s, "hello");sourcepub fn invalid(&self) -> bool
pub fn invalid(&self) -> bool
Check this Str for correctness.
When constructing/receiving a Str outside of
its constructors, it may not be guaranteed that
the invariants are upheld.
This function will return true if:
- Internal length is greater than the internal byte array
- Inner byte array is longer than
255 .as_str()would return invalid UTF-8
// Create `Str` with maximum 5 length.
let mut string = Str::<5>::new();
assert_eq!(string.invalid(), false);
// Unsafely set the length to 10.
unsafe { string.set_len(10); }
// This string is now invalid.
assert_eq!(string.invalid(), true);sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears all bytes of this Str.
// Create a string.
let mut s = Str::<5>::from_static_str("hello");
assert_eq!(s, "hello");
// Clear the string.
s.clear();
assert_eq!(s, "");
assert!(s.is_empty());Safety
This does not actually mutate any bytes,
it simply sets the internal length to 0.
Do not rely on this to clear the actual bytes.
sourcepub fn zero(&mut self)
pub fn zero(&mut self)
Zeros all bytes of this Str and sets the length to 0
Unlike Str::clear(), this actually sets all
the bytes in the internal array to 0.
// Create a string.
let mut s = Str::<5>::from_static_str("hello");
assert_eq!(s, "hello");
// Zero the string.
s.zero();
assert_eq!(s, "");
assert!(s.is_empty());sourcepub const fn is_empty(&self) -> bool
pub const fn is_empty(&self) -> bool
If this Str is empty.
let mut s = Str::<10>::new();
assert_eq!(s, "");
assert!(s.is_empty());
s.push_str("a").unwrap();
assert!(!s.is_empty());sourcepub const fn is_full(&self) -> bool
pub const fn is_full(&self) -> bool
If this Str is full (no more capacity left).
let mut s = Str::<3>::new();
assert_eq!(s.len(), 0);
assert!(!s.is_full());
s.push_str("123").unwrap();
assert_eq!(s.len(), 3);
assert!(s.is_full());sourcepub fn into_string(self) -> Stringwhere
Self: Sized,
pub fn into_string(self) -> Stringwhere
Self: Sized,
Consumes self into a String
let s = Str::<5>::from_static_str("hello");
let s: String = s.into_string();
assert_eq!(s, "hello");sourcepub fn copy_str(&mut self, s: impl AsRef<str>) -> Result<usize, usize>
pub fn copy_str(&mut self, s: impl AsRef<str>) -> Result<usize, usize>
Overwrites self with the str s.
The input s must be the exact same length
as N or this function will error.
If the copy was successful, Result::Ok is returned with the new length of the string.
If the copy failed because s.len() > N, Result::Err is returned with how many extra bytes couldn’t fit.
If the copy failed because s.len() != N, Result::Err is returned as Err(0).
let mut string = Str::<3>::new();
// Input string is 4 in length, we can't copy it.
// There is 1 extra byte that can't fit.
assert_eq!(string.copy_str("abcd"), Err(1));
// Input string is 2 in length, not exactly 3.
// `Err(0)` will be returned to indicate this.
assert_eq!(string.copy_str("ab"), Err(0));sourcepub fn copy_str_unchecked(&mut self, s: impl AsRef<str>) -> usize
pub fn copy_str_unchecked(&mut self, s: impl AsRef<str>) -> usize
Performs the same operation as Self::copy_str() except
this function does not check if the input str s is too long.
If the copy was successful, the new length of the string is returned.
If the copy failed, this function will panic.
let mut string = Str::<3>::new();
// Input string is 3 in length, we can copy it.
assert_eq!(string.copy_str_unchecked("abc"), 3);Panics
Instead of erroring, this function will panic if the input s.len() != N.
Input too long:
let mut string = Str::<3>::new();
// Input string is 5 in length, this will panic.
string.copy_str_unchecked("abcd");Input not long enough:
let mut string = Str::<3>::new();
// Input string is 2 in length, this will panic.
string.copy_str_unchecked("ab");Input is just right:
let mut string = Str::<3>::new();
string.copy_str_unchecked("abc");
assert_eq!(string, "abc")sourcepub fn push_str(&mut self, s: impl AsRef<str>) -> Result<usize, usize>
pub fn push_str(&mut self, s: impl AsRef<str>) -> Result<usize, usize>
Appends self with the str s.
If the push was successful (or s was empty),
Result::Ok is returned with the new length of the string.
If the push failed, Result::Err is returned
with how many extra bytes couldn’t fit.
let mut string = Str::<3>::new();
// Input string is 4 in length.
// We can't push it.
let err = string.push_str("abcd");
assert_eq!(err, Err(1));
// The string is still empty.
assert!(string.is_empty());
// This 2 length string will fit.
string.push_str("ab").unwrap();
assert_eq!(string, "ab");
// This 1 length string will fit.
string.push_str("c").unwrap();
assert_eq!(string, "abc");
// But not anymore.
let err = string.push_str("d");
assert_eq!(err, Err(1));
assert_eq!(string, "abc");sourcepub fn push_str_unchecked(&mut self, s: impl AsRef<str>) -> usize
pub fn push_str_unchecked(&mut self, s: impl AsRef<str>) -> usize
Appends self with the str s.
If the push was successful (or s was empty),
a usize is returned, representing the new length of the string.
let mut s = Str::<5>::new();
assert_eq!(s.push_str_unchecked("wow"), 3);Panics
If the push failed, this function panics.
Input string is > than capacity:
let mut s = Str::<3>::new();
s.push_str_unchecked("abcd");Str has no more remaining capacity:
let mut s = Str::<4>::from_static_str("wow");
assert_eq!(s.len(), 3);
assert_eq!(s.remaining(), 1);
// This won't fit, will panic.
s.push_str_unchecked("wow");sourcepub const unsafe fn from_raw(buf: [u8; N], len: u8) -> Self
pub const unsafe fn from_raw(buf: [u8; N], len: u8) -> Self
Creates a new Str from a byte array buffer and a length
let buf = [b'h', b'i', 0, 0, 0];
let len = 2;
// SAFETY: The length covers valid
// UTF-8 bytes in the provided buffer.
let s = unsafe { Str::<5>::from_raw(buf, len) };
assert_eq!(s, "hi");Safety
The caller needs to make sure the bytes covered
by the len are actual valid UTF-8 bytes.
sourcepub fn from_str_exact(string: &str) -> Self
pub fn from_str_exact(string: &str) -> Self
sourcepub fn from_bytes_exact(bytes: &[u8]) -> Self
pub fn from_bytes_exact(bytes: &[u8]) -> Self
Create a Str directly from bytes
let s = Str::<5>::from_bytes_exact(b"12345");
assert_eq!(s, "12345");Safety
The bytes must be valid UTF-8.
Panics
The input bytes bytes’s length must
be exactly equal to Self::CAPACITY or this
function will panic.
// 1 too many characters, will panic.
let s = Str::<4>::from_bytes_exact(b"12345");Trait Implementations§
source§impl<'__de, const N: usize> BorrowDecode<'__de> for Str<N>
impl<'__de, const N: usize> BorrowDecode<'__de> for Str<N>
source§fn borrow_decode<__D: BorrowDecoder<'__de>>(
decoder: &mut __D
) -> Result<Self, DecodeError>
fn borrow_decode<__D: BorrowDecoder<'__de>>( decoder: &mut __D ) -> Result<Self, DecodeError>
source§impl<'de, const N: usize> Deserialize<'de> for Str<N>
impl<'de, const N: usize> Deserialize<'de> for Str<N>
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> Ord for Str<N>
impl<const N: usize> Ord for Str<N>
source§impl<const N: usize> PartialEq<&str> for Str<N>
impl<const N: usize> PartialEq<&str> for Str<N>
source§impl<const N: usize> PartialEq for Str<N>
impl<const N: usize> PartialEq for Str<N>
source§impl<const N: usize> PartialOrd for Str<N>
impl<const N: usize> PartialOrd for Str<N>
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 moresource§impl<const N: usize> TryFrom<&Arc<str>> for Str<N>
impl<const N: usize> TryFrom<&Arc<str>> for Str<N>
source§fn try_from(string: &Arc<str>) -> Result<Self, Self::Error>
fn try_from(string: &Arc<str>) -> Result<Self, Self::Error>
This takes in a &str of any length (equal to or less than N)
and will return a Str with that same string.
If this function fails, Result::Err is returned with how many extra bytes couldn’t fit.
// Input string is 4 in length, we can't copy it.
// There is 1 extra byte that can't fit.
assert_eq!(Str::<3>::try_from("abcd"), Err(1));Compile-time panic
This function will panic at compile time if N > 255.
// Compile error!
Str::<256>::try_from("");source§impl<const N: usize> TryFrom<&Box<str>> for Str<N>
impl<const N: usize> TryFrom<&Box<str>> for Str<N>
source§fn try_from(string: &Box<str>) -> Result<Self, Self::Error>
fn try_from(string: &Box<str>) -> Result<Self, Self::Error>
This takes in a &str of any length (equal to or less than N)
and will return a Str with that same string.
If this function fails, Result::Err is returned with how many extra bytes couldn’t fit.
// Input string is 4 in length, we can't copy it.
// There is 1 extra byte that can't fit.
assert_eq!(Str::<3>::try_from("abcd"), Err(1));Compile-time panic
This function will panic at compile time if N > 255.
// Compile error!
Str::<256>::try_from("");source§impl<const N: usize> TryFrom<&Cow<'_, str>> for Str<N>
impl<const N: usize> TryFrom<&Cow<'_, str>> for Str<N>
source§fn try_from(string: &Cow<'_, str>) -> Result<Self, Self::Error>
fn try_from(string: &Cow<'_, str>) -> Result<Self, Self::Error>
This takes in a &str of any length (equal to or less than N)
and will return a Str with that same string.
If this function fails, Result::Err is returned with how many extra bytes couldn’t fit.
// Input string is 4 in length, we can't copy it.
// There is 1 extra byte that can't fit.
assert_eq!(Str::<3>::try_from("abcd"), Err(1));Compile-time panic
This function will panic at compile time if N > 255.
// Compile error!
Str::<256>::try_from("");source§impl<const N: usize> TryFrom<&Rc<str>> for Str<N>
impl<const N: usize> TryFrom<&Rc<str>> for Str<N>
source§fn try_from(string: &Rc<str>) -> Result<Self, Self::Error>
fn try_from(string: &Rc<str>) -> Result<Self, Self::Error>
This takes in a &str of any length (equal to or less than N)
and will return a Str with that same string.
If this function fails, Result::Err is returned with how many extra bytes couldn’t fit.
// Input string is 4 in length, we can't copy it.
// There is 1 extra byte that can't fit.
assert_eq!(Str::<3>::try_from("abcd"), Err(1));Compile-time panic
This function will panic at compile time if N > 255.
// Compile error!
Str::<256>::try_from("");source§impl<const N: usize> TryFrom<&String> for Str<N>
impl<const N: usize> TryFrom<&String> for Str<N>
source§fn try_from(string: &String) -> Result<Self, Self::Error>
fn try_from(string: &String) -> Result<Self, Self::Error>
This takes in a &str of any length (equal to or less than N)
and will return a Str with that same string.
If this function fails, Result::Err is returned with how many extra bytes couldn’t fit.
// Input string is 4 in length, we can't copy it.
// There is 1 extra byte that can't fit.
assert_eq!(Str::<3>::try_from("abcd"), Err(1));Compile-time panic
This function will panic at compile time if N > 255.
// Compile error!
Str::<256>::try_from("");source§impl<const N: usize> TryFrom<&str> for Str<N>
impl<const N: usize> TryFrom<&str> for Str<N>
source§fn try_from(string: &str) -> Result<Self, Self::Error>
fn try_from(string: &str) -> Result<Self, Self::Error>
This takes in a &str of any length (equal to or less than N)
and will return a Str with that same string.
If this function fails, Result::Err is returned with how many extra bytes couldn’t fit.
// Input string is 4 in length, we can't copy it.
// There is 1 extra byte that can't fit.
assert_eq!(Str::<3>::try_from("abcd"), Err(1));Compile-time panic
This function will panic at compile time if N > 255.
// Compile error!
Str::<256>::try_from("");source§impl<const N: usize> TryFrom<Arc<str>> for Str<N>
impl<const N: usize> TryFrom<Arc<str>> for Str<N>
source§fn try_from(string: Arc<str>) -> Result<Self, Self::Error>
fn try_from(string: Arc<str>) -> Result<Self, Self::Error>
This takes in a &str of any length (equal to or less than N)
and will return a Str with that same string.
If this function fails, Result::Err is returned with how many extra bytes couldn’t fit.
// Input string is 4 in length, we can't copy it.
// There is 1 extra byte that can't fit.
assert_eq!(Str::<3>::try_from("abcd"), Err(1));Compile-time panic
This function will panic at compile time if N > 255.
// Compile error!
Str::<256>::try_from("");source§impl<const N: usize> TryFrom<Box<str>> for Str<N>
impl<const N: usize> TryFrom<Box<str>> for Str<N>
source§fn try_from(string: Box<str>) -> Result<Self, Self::Error>
fn try_from(string: Box<str>) -> Result<Self, Self::Error>
This takes in a &str of any length (equal to or less than N)
and will return a Str with that same string.
If this function fails, Result::Err is returned with how many extra bytes couldn’t fit.
// Input string is 4 in length, we can't copy it.
// There is 1 extra byte that can't fit.
assert_eq!(Str::<3>::try_from("abcd"), Err(1));Compile-time panic
This function will panic at compile time if N > 255.
// Compile error!
Str::<256>::try_from("");source§impl<const N: usize> TryFrom<Cow<'_, str>> for Str<N>
impl<const N: usize> TryFrom<Cow<'_, str>> for Str<N>
source§fn try_from(string: Cow<'_, str>) -> Result<Self, Self::Error>
fn try_from(string: Cow<'_, str>) -> Result<Self, Self::Error>
This takes in a &str of any length (equal to or less than N)
and will return a Str with that same string.
If this function fails, Result::Err is returned with how many extra bytes couldn’t fit.
// Input string is 4 in length, we can't copy it.
// There is 1 extra byte that can't fit.
assert_eq!(Str::<3>::try_from("abcd"), Err(1));Compile-time panic
This function will panic at compile time if N > 255.
// Compile error!
Str::<256>::try_from("");source§impl<const N: usize> TryFrom<Rc<str>> for Str<N>
impl<const N: usize> TryFrom<Rc<str>> for Str<N>
source§fn try_from(string: Rc<str>) -> Result<Self, Self::Error>
fn try_from(string: Rc<str>) -> Result<Self, Self::Error>
This takes in a &str of any length (equal to or less than N)
and will return a Str with that same string.
If this function fails, Result::Err is returned with how many extra bytes couldn’t fit.
// Input string is 4 in length, we can't copy it.
// There is 1 extra byte that can't fit.
assert_eq!(Str::<3>::try_from("abcd"), Err(1));Compile-time panic
This function will panic at compile time if N > 255.
// Compile error!
Str::<256>::try_from("");source§impl<const N: usize> TryFrom<String> for Str<N>
impl<const N: usize> TryFrom<String> for Str<N>
source§fn try_from(string: String) -> Result<Self, Self::Error>
fn try_from(string: String) -> Result<Self, Self::Error>
This takes in a &str of any length (equal to or less than N)
and will return a Str with that same string.
If this function fails, Result::Err is returned with how many extra bytes couldn’t fit.
// Input string is 4 in length, we can't copy it.
// There is 1 extra byte that can't fit.
assert_eq!(Str::<3>::try_from("abcd"), Err(1));Compile-time panic
This function will panic at compile time if N > 255.
// Compile error!
Str::<256>::try_from("");impl<const N: usize> Copy for Str<N>
impl<const N: usize> Eq for Str<N>
impl<const N: usize> StructuralEq for Str<N>
impl<const N: usize> StructuralPartialEq for Str<N>
Auto Trait Implementations§
impl<const N: usize> RefUnwindSafe for Str<N>
impl<const N: usize> Send for Str<N>
impl<const N: usize> Sync for Str<N>
impl<const N: usize> Unpin for Str<N>
impl<const N: usize> UnwindSafe for Str<N>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> HeadTail for T
impl<T> HeadTail for T
source§fn head_tail_dot(&self, head: usize, tail: usize) -> HeadTailDot<'_>
fn head_tail_dot(&self, head: usize, tail: usize) -> HeadTailDot<'_>
source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
source§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more