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>
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.
Trait Implementations§
Source§impl PanicFmt for Separator<'_>
impl PanicFmt for Separator<'_>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more