Struct const_panic::ArrayString
source · [−]pub struct ArrayString<const CAP: usize> { /* private fields */ }
Available on crate feature
non_basic
only.Expand description
For precomputing a panic message.
Implementations
sourceimpl<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",
);
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
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!");
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, 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!");
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
sourceimpl<const CAP: usize> Clone for ArrayString<CAP>
impl<const CAP: usize> Clone for ArrayString<CAP>
sourcefn clone(&self) -> ArrayString<CAP>
fn clone(&self) -> ArrayString<CAP>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresourceimpl<const CAP: usize> Debug for ArrayString<CAP>
impl<const CAP: usize> Debug for ArrayString<CAP>
sourceimpl<const CAP: usize> PanicFmt for ArrayString<CAP>
impl<const CAP: usize> PanicFmt for ArrayString<CAP>
type This = ArrayString<CAP>
type This = ArrayString<CAP>
The type after dereferencing all references. Read more
type Kind = IsCustomType
type Kind = IsCustomType
Whether this is a user-defined type or standard library type. Read more
sourceimpl<const CAP: usize> PartialEq<&str> for ArrayString<CAP>
impl<const CAP: usize> PartialEq<&str> for ArrayString<CAP>
sourceimpl<const CAP: usize> PartialEq<str> for ArrayString<CAP>
impl<const CAP: usize> PartialEq<str> for ArrayString<CAP>
impl<const CAP: usize> Copy for ArrayString<CAP>
Auto Trait Implementations
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
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more