Enum const_panic::fmt::Delimiter
source · [−]#[non_exhaustive]
pub enum Delimiter {
OpenParen,
CloseParen,
OpenBracket,
CloseBracket,
OpenBrace,
CloseBrace,
Empty,
}
Available on crate feature
non_basic
only.Expand description
For outputting an alternate flag-aware delimiter.
This was created for formatting structs and enum variants,
so these delimiters have spaces around them to follow the
Foo { bar: baz }
, Foo(bar)
, and [foo, bar]
style.
Example
use const_panic::{
fmt::{self, FmtArg},
ArrayString,
flatten_panicvals,
};
// Debug formatting
assert_eq!(
ArrayString::<999>::from_panicvals(
&flatten_panicvals!(FmtArg::DEBUG;
open: fmt::EmptyDelimiter,
100u8, fmt::COMMA_SEP,
false, fmt::COMMA_SEP,
[0u16; 0], fmt::COMMA_SEP,
// parenthesizing to pass this as a non-literal
// otherwise the string is Display formatted
("really"), fmt::COMMA_TERM,
close: "",
)
).unwrap(),
" 100, false, [], \"really\""
);
// Alternate-Debug formatting
assert_eq!(
ArrayString::<999>::from_panicvals(
&flatten_panicvals!(FmtArg::ALT_DEBUG;
open: fmt::EmptyDelimiter,
100u8, fmt::COMMA_SEP,
false, fmt::COMMA_SEP,
[0u16; 0], fmt::COMMA_SEP,
("really"), fmt::COMMA_TERM,
close: "",
)
).unwrap(),
concat!(
"\n",
" 100,\n",
" false,\n",
" [],\n",
" \"really\",\n",
)
);
Variants (Non-exhaustive)
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
OpenParen
(
CloseParen
)
OpenBracket
[
CloseBracket
]
OpenBrace
{
CloseBrace
}
Empty
An empty delimiter, exists only to add whitespace on the next line when the alternate flag is enabled.
Implementations
sourceimpl Delimiter
impl Delimiter
sourcepub const fn to_panicvals(self, f: FmtArg) -> [PanicVal<'static>; 1]
pub const fn to_panicvals(self, f: FmtArg) -> [PanicVal<'static>; 1]
Converts this Delimiter
into an array of one PanicVal
When the alternate flag is enabled, this and the to_panicval
method output:
- the delimiter
- a newline
- fmtarg.indentation amount of spaces
When the alternate flag is disabled, these methods output braces with spaces around them, the empty delimiter as one space, and the remaining delimiters with no spaces around them.
sourcepub const fn to_panicval(self, f: FmtArg) -> PanicVal<'static>
pub const fn to_panicval(self, f: FmtArg) -> PanicVal<'static>
Converts this Delimiter
into a PanicVal
Trait Implementations
sourceimpl PanicFmt for Delimiter
impl PanicFmt for Delimiter
impl Copy for Delimiter
impl Eq for Delimiter
impl StructuralEq for Delimiter
impl StructuralPartialEq for Delimiter
Auto Trait Implementations
impl RefUnwindSafe for Delimiter
impl Send for Delimiter
impl Sync for Delimiter
impl Unpin for Delimiter
impl UnwindSafe for Delimiter
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
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