TemplateFormatter

Enum TemplateFormatter 

Source
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.

Fields

§spec: Option<Box<str>>

Raw display format specifier (for example ">8" or “.3”).

§

Debug

Debug formatting ({value:?} or {value:#?}).

Fields

§alternate: bool

Whether {value:#?} (alternate debug) was requested.

§

LowerHex

Lower-hexadecimal formatting ({value:x} / {value:#x}).

Fields

§alternate: bool

Whether alternate formatting ({value:#x}) was requested.

§

UpperHex

Upper-hexadecimal formatting ({value:X} / {value:#X}).

Fields

§alternate: bool

Whether alternate formatting ({value:#X}) was requested.

§

Pointer

Pointer formatting ({value:p} / {value:#p}).

Fields

§alternate: bool

Whether alternate formatting ({value:#p}) was requested.

§

Binary

Binary formatting ({value:b} / {value:#b}).

Fields

§alternate: bool

Whether alternate formatting ({value:#b}) was requested.

§

Octal

Octal formatting ({value:o} / {value:#o}).

Fields

§alternate: bool

Whether alternate formatting ({value:#o}) was requested.

§

LowerExp

Lower exponential formatting ({value:e} / {value:#e}).

Fields

§alternate: bool

Whether alternate formatting ({value:#e}) was requested.

§

UpperExp

Upper exponential formatting ({value:E} / {value:#E}).

Fields

§alternate: bool

Whether alternate formatting ({value:#E}) was requested.

Implementations§

Source§

impl TemplateFormatter

Source

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
    }
));
Source

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);
Source

pub fn from_format_spec(spec: &str) -> Option<Self>

Parses a formatting specifier (the portion after :) into a formatter.

Source

pub fn display_spec(&self) -> Option<&str>

Returns the stored display format specifier, if any.

Source

pub fn has_display_spec(&self) -> bool

Indicates whether a display formatter carries additional formatting parameters.

Source

pub fn format_fragment(&self) -> Option<Cow<'_, str>>

Returns the formatter fragment that should follow the : in a format string.

Source

pub const fn is_alternate(&self) -> bool

Returns true when alternate formatting (#) was requested.

Trait Implementations§

Source§

impl Clone for TemplateFormatter

Source§

fn clone(&self) -> TemplateFormatter

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TemplateFormatter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for TemplateFormatter

Source§

fn eq(&self, other: &TemplateFormatter) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for TemplateFormatter

Source§

impl StructuralPartialEq for TemplateFormatter

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.