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§

source§

impl<'a> Separator<'a>

source

pub const fn new(string: &'a str, is_last_field: IsLast) -> Self

Constructs a Separator from a custom separator.

Panics

Panics if string is longer than 12 bytes.

source

pub const fn to_panicvals(self, f: FmtArg) -> [PanicVal<'static>; 1]

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

source

pub const fn to_panicval(self, f: FmtArg) -> PanicVal<'static>

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§

source§

impl<'a> Clone for Separator<'a>

source§

fn clone(&self) -> Separator<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl PanicFmt for Separator<'_>

§

type This = Separator<'_>

The type after dereferencing all references. Read more
§

type Kind = IsCustomType

Whether this is a user-defined type or standard library type. Read more
source§

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§

const PROOF: IsPanicFmt<Self, Self::This, Self::Kind> = IsPanicFmt::NEW

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

impl<'a> Copy for Separator<'a>

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for Separator<'a>

§

impl<'a> Send for Separator<'a>

§

impl<'a> Sync for Separator<'a>

§

impl<'a> Unpin for Separator<'a>

§

impl<'a> UnwindSafe for Separator<'a>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, W> HasTypeWitness<W> for Twhere W: MakeTypeWitness<Arg = T>, T: ?Sized,

source§

const WITNESS: W = W::MAKE

A constant of the type witness
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.