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>
impl<'a> Separator<'a>
sourcepub const fn to_panicvals(self, f: FmtArg) -> [PanicVal<'static>; 1]
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
sourcepub const fn to_panicval(self, f: FmtArg) -> PanicVal<'static>
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:
- the separator
- a newline
- fmtarg.indentation amount of spaces
if constructed with
IsLast::No
When the alternate flag is disabled,
these methods output the separator and a single space
if constructed with IsLast::No
,
otherwise output nothing.