Struct const_panic::fmt::Separator [−][src]
pub struct Separator<'a>(_, _);
This is supported 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!(
ArrayString::<999>::from_panicvals(
&flatten_panicvals!(FmtArg::DEBUG;
open: fmt::OpenBrace,
debug: "foo", SEMICOLON_SEP,
[3u8, 5, 8], SEMICOLON_SEP,
false, SEMICOLON_TERM,
close: fmt::CloseBrace,
)
).unwrap(),
// 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!(
ArrayString::<999>::from_panicvals(
&flatten_panicvals!(FmtArg::ALT_DEBUG;
open: fmt::OpenBrace,
debug: "foo", SEMICOLON_SEP,
debug: [3u8, 5, 8], SEMICOLON_SEP,
false, SEMICOLON_TERM,
close: fmt::CloseBrace,
)
).unwrap(),
concat!(
" {\n",
" \"foo\";\n",
" [3, 5, 8];\n",
" false;\n",
"}",
)
);
Implementations
Converts this Separator
into an array of one PanicVal
.
Otherwise does the same as to_panicval
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.
Trait Implementations
type Kind = IsCustomType
type Kind = IsCustomType
Whether this is a user-defined type or standard library type. Read more
The length of the array returned in Self::to_panicvals
(an inherent method that formats the type for panic messages). Read more