pub enum TemplateFormatter {
Display {
spec: Option<Box<str>>,
},
Debug {
alternate: bool,
},
LowerHex {
alternate: bool,
},
UpperHex {
alternate: bool,
},
Pointer {
alternate: bool,
},
Binary {
alternate: bool,
},
Octal {
alternate: bool,
},
LowerExp {
alternate: bool,
},
UpperExp {
alternate: bool,
},
}Expand description
Formatting mode requested by the placeholder.
Variants§
Display
Default Display formatting ({value}) with an optional format spec.
Debug
Debug formatting ({value:?} or {value:#?}).
LowerHex
Lower-hexadecimal formatting ({value:x} / {value:#x}).
UpperHex
Upper-hexadecimal formatting ({value:X} / {value:#X}).
Pointer
Pointer formatting ({value:p} / {value:#p}).
Binary
Binary formatting ({value:b} / {value:#b}).
Octal
Octal formatting ({value:o} / {value:#o}).
LowerExp
Lower exponential formatting ({value:e} / {value:#e}).
UpperExp
Upper exponential formatting ({value:E} / {value:#E}).
Implementations§
Source§impl TemplateFormatter
impl TemplateFormatter
Sourcepub const fn from_kind(kind: TemplateFormatterKind, alternate: bool) -> Self
pub const fn from_kind(kind: TemplateFormatterKind, alternate: bool) -> Self
Constructs a formatter from a TemplateFormatterKind and alternate
flag.
The alternate flag is ignored for TemplateFormatterKind::Display.
§Examples
use masterror_template::template::{TemplateFormatter, TemplateFormatterKind};
let formatter = TemplateFormatter::from_kind(TemplateFormatterKind::Binary, true);
assert!(matches!(
formatter,
TemplateFormatter::Binary {
alternate: true
}
));Sourcepub const fn kind(&self) -> TemplateFormatterKind
pub const fn kind(&self) -> TemplateFormatterKind
Returns the underlying formatter kind.
§Examples
use masterror_template::template::{TemplateFormatter, TemplateFormatterKind};
let formatter = TemplateFormatter::Pointer {
alternate: false
};
assert_eq!(formatter.kind(), TemplateFormatterKind::Pointer);Sourcepub fn from_format_spec(spec: &str) -> Option<Self>
pub fn from_format_spec(spec: &str) -> Option<Self>
Parses a formatting specifier (the portion after :) into a formatter.
Sourcepub fn display_spec(&self) -> Option<&str>
pub fn display_spec(&self) -> Option<&str>
Returns the stored display format specifier, if any.
Sourcepub fn has_display_spec(&self) -> bool
pub fn has_display_spec(&self) -> bool
Indicates whether a display formatter carries additional formatting parameters.
Sourcepub fn format_fragment(&self) -> Option<Cow<'_, str>>
pub fn format_fragment(&self) -> Option<Cow<'_, str>>
Returns the formatter fragment that should follow the : in a format
string.
Sourcepub const fn is_alternate(&self) -> bool
pub const fn is_alternate(&self) -> bool
Returns true when alternate formatting (#) was requested.
Trait Implementations§
Source§impl Clone for TemplateFormatter
impl Clone for TemplateFormatter
Source§fn clone(&self) -> TemplateFormatter
fn clone(&self) -> TemplateFormatter
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more