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
let array = StdWrapper(&["3", "foo\nbar", "\0qux"]);
// Debug formatting
assert_eq!(
ArrayString::<99>::from_panicvals(&array.to_panicvals(FmtArg::DEBUG)).unwrap(),
r#"["3", "foo\nbar", "\x00qux"]"#
);
// Alternate-Debug formatting
assert_eq!(
ArrayString::<99>::from_panicvals(&array.to_panicvals(FmtArg::ALT_DEBUG)).unwrap(),
concat!(
"[\n",
" \"3\",\n",
" \"foo\\nbar\",\n",
" \"\\x00qux\",\n",
"]",
)
);
// Display formatting
assert_eq!(
ArrayString::<99>::from_panicvals(&array.to_panicvals(FmtArg::DISPLAY)).unwrap(),
"[3, foo\nbar, \x00qux]"
);
// Alternate-Display formatting
assert_eq!(
ArrayString::<99>::from_panicvals(&array.to_panicvals(FmtArg::ALT_DISPLAY)).unwrap(),
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
sourceimpl FmtArg
impl FmtArg
sourcepub const fn pack(self) -> PackedFmtArg
Available on crate feature non_basic
only.
pub const fn pack(self) -> PackedFmtArg
non_basic
only.Converts this FmtArg
into a PackedFmtArg
,
which is smaller but can only be converted back into a FmtArg
.
sourceimpl FmtArg
impl FmtArg
sourcepub const ALT_DISPLAY: Self = _
pub const ALT_DISPLAY: Self = _
A FmtArg
with alternate Display
formatting, starting with no indentation.
sourcepub const ALT_DEBUG: Self = _
pub const ALT_DEBUG: Self = _
A FmtArg
with alternate Debug
formatting, starting with no indentation.
sourcepub const ALT_BIN: Self = _
pub const ALT_BIN: Self = _
A FmtArg
with alternate Debug
and Binary
formatting,
starting with no indentation.
sourcepub const ALT_HEX: Self = _
pub const ALT_HEX: Self = _
A FmtArg
with alternate Debug
and Hexadecimal
formatting,
starting with no indentation.
sourcepub const fn set_alternate(self, is_alternate: bool) -> Self
pub const fn set_alternate(self, is_alternate: bool) -> Self
Sets whether alternate formatting is enabled
sourcepub const fn set_display(self) -> Self
pub const fn set_display(self) -> Self
Changes the formatting to Display
.
sourceimpl FmtArg
impl FmtArg
sourcepub const fn indent(self) -> Self
Available on crate feature non_basic
only.
pub const fn indent(self) -> Self
non_basic
only.Increments the indentation by INDENTATION_STEP
spaces.
sourcepub const fn unindent(self) -> Self
Available on crate feature non_basic
only.
pub const fn unindent(self) -> Self
non_basic
only.Decrement the indentation by INDENTATION_STEP
spaces.
Trait Implementations
impl Copy for FmtArg
impl StructuralPartialEq for FmtArg
Auto Trait Implementations
impl RefUnwindSafe for FmtArg
impl Send for FmtArg
impl Sync for FmtArg
impl Unpin for FmtArg
impl UnwindSafe for FmtArg
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more