Struct const_panic::ArrayString [−][src]
pub struct ArrayString<const CAP: usize> { /* fields omitted */ }
This is supported on crate feature
non_basic
only.Expand description
For precomputing a panic message.
Implementations
Constructs this string from a &[&[PanicVal<'_>]]
.
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(),
);
Constructs this string from a &[PanicVal<'_>]
.
Example
use const_panic::{ArrayString, FmtArg, flatten_panicvals};
assert_eq!(
ArrayString::<8>::from_panicvals(
&flatten_panicvals!(FmtArg::DEBUG; 100u8, "hello")
).unwrap(),
"100hello",
);
assert!(
ArrayString::<7>::from_panicvals(
&flatten_panicvals!(FmtArg::DEBUG; 100u8, "hello")
).is_none(),
);
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);
Accesses the string as a byte slice.
Performance
This takes a linear amount of time to run, proportional to CAP - self.len()
.
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!");
Gets the string.
Performance
This takes a linear amount of time to run, proportional to CAP - self.len()
.
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!");
Creates a single element PanicVal
borrowing from this string.
Creates a PanicVal
borrowing from this string.
Trait Implementations
type Kind = IsCustomType
type Kind = IsCustomType
Whether this is a user-defined type or standard library type. Read more
The length of the array returned in Self::to_panicvals
(an inherent method that formats the type for panic messages). Read more