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 an ArrayString from a &str

Panics

Panics if string is larger than CAP.

Example
use const_panic::ArrayString;

assert_eq!(ArrayString::<16>::new("Hello, world!"), "Hello, world!");

Constructs an ArrayString by concatenating zero or more &strs

Panics

Panics if the concatenated string would be longer than CAP.

Example
use const_panic::ArrayString;

assert_eq!(
    ArrayString::<99>::concat(&["This ", "is ", "a string"]),
    "This is a string"
);

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(),
);

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(),
);

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

The type after dereferencing all references. Read more

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

A marker type that proves that Self implements PanicFmt. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.