pub struct ArrayString<const CAP: usize> { /* private fields */ }Expand description
For precomputing a panic message.
Implementations§
Source§impl<const CAP: usize> ArrayString<CAP>
impl<const CAP: usize> ArrayString<CAP>
Sourcepub const fn concat_panicvals(args: &[&[PanicVal<'_>]]) -> Option<Self>
pub const fn concat_panicvals(args: &[&[PanicVal<'_>]]) -> Option<Self>
Constructs this string from a &[&[PanicVal<'_>]].
Returns None if the formatted args would be larger than CAP.
§Example
use const_panic::{ArrayString, FmtArg, flatten_panicvals};
assert_eq!(
ArrayString::<17>::concat_panicvals(&[
&flatten_panicvals!(FmtArg::DEBUG; 1u8, ("hello")),
&flatten_panicvals!(FmtArg::DEBUG; &[3u8, 5, 8]),
]).unwrap(),
"1\"hello\"[3, 5, 8]",
);
assert!(
ArrayString::<16>::concat_panicvals(&[
&flatten_panicvals!(FmtArg::DEBUG; 1u8, ("hello")),
&flatten_panicvals!(FmtArg::DEBUG; &[3u8, 5, 8]),
]).is_none(),
);
Sourcepub const fn from_panicvals(args: &[PanicVal<'_>]) -> Option<Self>
pub const fn from_panicvals(args: &[PanicVal<'_>]) -> Option<Self>
Constructs this string from a &[PanicVal<'_>].
Returns None if the formatted args would be larger than CAP.
§Example
use const_panic::{ArrayString, FmtArg, flatten_panicvals};
assert_eq!(
ArrayString::<8>::from_panicvals(
&flatten_panicvals!(FmtArg::DEBUG; 100u8, "hello")
).unwrap(),
"100hello",
);
// trying to format panicvals into too small an ArrayString
assert!(
ArrayString::<7>::from_panicvals(
&flatten_panicvals!(FmtArg::DEBUG; 100u8, "hello")
).is_none(),
);
Sourcepub const fn len(&self) -> usize
pub const fn len(&self) -> usize
How long the string is in bytes.
§Example
use const_panic::ArrayString;
assert_eq!(ArrayString::<16>::new("foo").len(), 3);
assert_eq!(ArrayString::<16>::new("foo bar").len(), 7);
assert_eq!(ArrayString::<16>::new("Hello, world!").len(), 13);Sourcepub const fn as_bytes(&self) -> &[u8]
pub const fn as_bytes(&self) -> &[u8]
Accesses the string as a byte slice.
§Performance
When the “rust_1_64” feature is disabled,
this takes a linear amount of time to run, proportional to CAP - self.len().
When the “rust_1_64” feature is enabled, this takes a constant amount of time to run.
§Example
use const_panic::ArrayString;
assert_eq!(ArrayString::<16>::new("foo").as_bytes(), b"foo");
assert_eq!(ArrayString::<16>::new("foo bar").as_bytes(), b"foo bar");
assert_eq!(ArrayString::<16>::new("Hello, world!").as_bytes(), b"Hello, world!");Sourcepub const fn to_str(&self) -> &str
pub const fn to_str(&self) -> &str
Gets the string.
§Performance
This takes a linear amount of time to run.
§Example
use const_panic::ArrayString;
assert_eq!(ArrayString::<16>::new("foo").to_str(), "foo");
assert_eq!(ArrayString::<16>::new("foo bar").to_str(), "foo bar");
assert_eq!(ArrayString::<16>::new("Hello, world!").to_str(), "Hello, world!");Sourcepub const fn to_panicvals(&self, f: FmtArg) -> [PanicVal<'_>; 1]
pub const fn to_panicvals(&self, f: FmtArg) -> [PanicVal<'_>; 1]
Creates a single element PanicVal borrowing from this string.
Sourcepub const fn to_panicval(&self, f: FmtArg) -> PanicVal<'_>
pub const fn to_panicval(&self, f: FmtArg) -> PanicVal<'_>
Creates a PanicVal borrowing from this string.
Trait Implementations§
Source§impl<const CAP: usize> Clone for ArrayString<CAP>
impl<const CAP: usize> Clone for ArrayString<CAP>
Source§fn clone(&self) -> ArrayString<CAP>
fn clone(&self) -> ArrayString<CAP>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<const CAP: usize> Debug for ArrayString<CAP>
impl<const CAP: usize> Debug for ArrayString<CAP>
Source§impl<const CAP: usize> PanicFmt for ArrayString<CAP>
impl<const CAP: usize> PanicFmt for ArrayString<CAP>
Source§const PV_COUNT: usize = 1usize
const PV_COUNT: usize = 1usize
The length of the array returned in
Self::to_panicvals
(an inherent method that formats the type for panic messages).Source§type This = ArrayString<CAP>
type This = ArrayString<CAP>
The type after dereferencing all references. Read more
Source§type Kind = IsCustomType
type Kind = IsCustomType
Whether this is a user-defined type or standard library type. Read more
impl<const CAP: usize> Copy for ArrayString<CAP>
Auto Trait Implementations§
impl<const CAP: usize> Freeze for ArrayString<CAP>
impl<const CAP: usize> RefUnwindSafe for ArrayString<CAP>
impl<const CAP: usize> Send for ArrayString<CAP>
impl<const CAP: usize> Sync for ArrayString<CAP>
impl<const CAP: usize> Unpin for ArrayString<CAP>
impl<const CAP: usize> UnwindSafe for ArrayString<CAP>
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
Mutably borrows from an owned value. Read more