Struct Separator

Source
pub struct Separator<'a>(/* private fields */);
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 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 Separator<'_>

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 = Separator<'_>

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<'a> Copy for Separator<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Separator<'a>

§

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 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.