Enum Delimiter

Source
#[non_exhaustive]
pub enum Delimiter { OpenParen, CloseParen, OpenBracket, CloseBracket, OpenBrace, CloseBrace, Empty, }
Expand description

For outputting an alternate flag-aware delimiter.

This was created for formatting structs and enum variants, so these delimiters have spaces around them to follow the
Foo { bar: baz }, Foo(bar), and [foo, bar] style.

§Example

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

// Debug formatting
assert_eq!(
    const_panic::concat_!(FmtArg::DEBUG;
        open: fmt::EmptyDelimiter,
            100u8, fmt::COMMA_SEP,
            false, fmt::COMMA_SEP,
            [0u16; 0], fmt::COMMA_SEP,
            // parenthesizing to pass this as a non-literal
            // otherwise the string is Display formatted
            ("really"), fmt::COMMA_TERM,
        close: "",
    ),
    " 100, false, [], \"really\""
);


// Alternate-Debug formatting
assert_eq!(
    const_panic::concat_!(FmtArg::ALT_DEBUG;
        open: fmt::EmptyDelimiter,
            100u8, fmt::COMMA_SEP,
            false, fmt::COMMA_SEP,
            [0u16; 0], fmt::COMMA_SEP,
            ("really"), fmt::COMMA_TERM,
        close: "",
    ),
    concat!(
        "\n",
        "    100,\n",
        "    false,\n",
        "    [],\n",
        "    \"really\",\n",
    )
);

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

OpenParen

(

§

CloseParen

)

§

OpenBracket

[

§

CloseBracket

]

§

OpenBrace

{

§

CloseBrace

}

§

Empty

An empty delimiter, exists only to add whitespace on the next line when the alternate flag is enabled.

Implementations§

Source§

impl Delimiter

Source

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

Converts this Delimiter into an array of one PanicVal

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

When the alternate flag is disabled, these methods output braces with spaces around them, the empty delimiter as one space, and the remaining delimiters with no spaces around them.

Source

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

Converts this Delimiter into a PanicVal

Trait Implementations§

Source§

impl Clone for Delimiter

Source§

fn clone(&self) -> Delimiter

Returns a duplicate 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 Delimiter

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§

type This = Delimiter

The type after dereferencing all references. Read more
Source§

type Kind = IsCustomType

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

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

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

impl PartialEq for Delimiter

Source§

fn eq(&self, other: &Delimiter) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Delimiter

Source§

impl Eq for Delimiter

Source§

impl StructuralPartialEq for Delimiter

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

impl<T> Identity for T
where T: ?Sized,

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
Source§

impl<T, U> Into<U> for T
where 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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.