Struct const_panic::fmt::Separator

source ·
pub struct Separator<'a>(_, _);
Available on crate feature non_basic only.
Expand description

For alternate flag-aware separation of fields, collection elements, etc.

Example

use const_panic::{
    fmt::{self, FmtArg, IsLast, Separator},
    ArrayString,
    flatten_panicvals,
};

const SEMICOLON_SEP: Separator = Separator::new(";", IsLast::No);
const SEMICOLON_TERM: Separator = Separator::new(";", IsLast::Yes);

// Debug formatting
assert_eq!(
    const_panic::concat_!(FmtArg::DEBUG;
        open: fmt::OpenBrace,
            debug: "foo", SEMICOLON_SEP,
            [3u8, 5, 8], SEMICOLON_SEP,
            false, SEMICOLON_TERM,
        close: fmt::CloseBrace,
    ),
    // the space before the brace is because Delimiter is intended for
    // formatting structs and enum variants.
    " { \"foo\"; [3, 5, 8]; false }"
);


// Alternate-Debug formatting
assert_eq!(
    const_panic::concat_!(FmtArg::ALT_DEBUG;
        open: fmt::OpenBrace,
            debug: "foo", SEMICOLON_SEP,
            debug: [3u8, 5, 8], SEMICOLON_SEP,
            false, SEMICOLON_TERM,
        close: fmt::CloseBrace,
    ),
    concat!(
        " {\n",
        "    \"foo\";\n",
        "    [3, 5, 8];\n",
        "    false;\n",
        "}",
    )
);

Implementations§

Constructs a Separator from a custom separator.

Panics

Panics if string is longer than 12 bytes.

Converts this Separator into an array of one PanicVal. Otherwise does the same as to_panicval

Converts this Separator into a PanicVal.

When the alternate flag is enabled, this and the to_panicvals method output:

When the alternate flag is disabled, these methods output the separator and a single space if constructed with IsLast::No, otherwise output nothing.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. 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

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

Returns the argument unchanged.

A constant of the type witness

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

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.