Struct const_panic::fmt::FmtArg

source ·
pub struct FmtArg {
    pub indentation: u8,
    pub is_alternate: bool,
    pub fmt_kind: FmtKind,
    pub number_fmt: NumberFmt,
}
Expand description

Carries all of the configuration for formatting functions.

Example

use const_panic::{ArrayString, FmtArg, StdWrapper};

// `StdWrapper` wraps references to std types to provide their `to_panicvals` methods
const ARRAY: &[&str] = &["3", "foo\nbar", "\0qux"];

// Debug formatting
assert_eq!(
    const_panic::concat_!(FmtArg::DEBUG; ARRAY),
    r#"["3", "foo\nbar", "\x00qux"]"#
);

// Alternate-Debug formatting
assert_eq!(
    const_panic::concat_!(FmtArg::ALT_DEBUG; ARRAY),
    concat!(
        "[\n",
        "    \"3\",\n",
        "    \"foo\\nbar\",\n",
        "    \"\\x00qux\",\n",
        "]",
    )
);

// Display formatting
assert_eq!(
    const_panic::concat_!(FmtArg::DISPLAY; ARRAY),
    "[3, foo\nbar, \x00qux]"
);

// Alternate-Display formatting
assert_eq!(
    const_panic::concat_!(FmtArg::ALT_DISPLAY; ARRAY),
    concat!(
        "[\n",
        "    3,\n",
        "    foo\n",
        "bar,\n",
        "    \x00qux,\n",
        "]",
    )
);

Fields§

§indentation: u8

How much indentation is needed for a field/array element.

Indentation is used by fmt::Delimiter and by fmt::Separator, when the is_alternate field flag is enabled.

§is_alternate: bool

Whether alternate formatting is being used.

§fmt_kind: FmtKind

Whether this is intended to be Display or Debug formatted.

§number_fmt: NumberFmt

What integers are formatted as: decimal, hexadecimal, or binary.

Implementations§

Available on crate feature non_basic only.

Converts this FmtArg into a PackedFmtArg, which is smaller but can only be converted back into a FmtArg.

A FmtArg with no indentation and Display formatting.

A FmtArg with alternate Display formatting, starting with no indentation.

A FmtArg with Debug formatting and no indentation.

A FmtArg with alternate Debug formatting, starting with no indentation.

A FmtArg with Debug and Binary formatting and no indentation.

A FmtArg with alternate Debug and Binary formatting, starting with no indentation.

A FmtArg with Debug and Hexadecimal formatting and no indentation.

A FmtArg with alternate Debug and Hexadecimal formatting, starting with no indentation.

Sets whether alternate formatting is enabled

Changes the formatting to Display.

Changes the formatting to Debug.

Changes the formatting to Debug, and number formatting to Hexadecimal.

Changes the formatting to Debug, and number formatting to Binary.

Available on crate feature non_basic only.

Increments the indentation by INDENTATION_STEP spaces.

Available on crate feature non_basic only.

Decrement the indentation by INDENTATION_STEP spaces.

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
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. 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.