pub struct Formatter<'a> { /* private fields */ }Expand description
The per-value formatting context passed to DynDisplay::dyn_fmt.
This type mirrors std::fmt::Formatter: it bundles the FormatSpec with
the output sink and exposes convenience methods for writing padded output.
It implements std::fmt::Write, so write!(f, ...) works naturally inside
a DynDisplay::dyn_fmt implementation.
§Examples
Using write! directly — padding is applied automatically:
use dyf::{DynDisplay, Formatter};
use std::fmt::Write;
struct Point { x: i32, y: i32 }
impl DynDisplay for Point {
fn dyn_fmt(&self, f: &mut Formatter<'_>) -> dyf::Result {
Ok(write!(f, "Point({}, {})", self.x, self.y)?)
}
}Implementations§
Source§impl<'a> Formatter<'a>
impl<'a> Formatter<'a>
Sourcepub fn new(spec: &'a FormatSpec, out: &'a mut dyn Write) -> Self
pub fn new(spec: &'a FormatSpec, out: &'a mut dyn Write) -> Self
Creates a new Formatter wrapping the given spec and output sink.
Sourcepub fn spec(&self) -> &FormatSpec
pub fn spec(&self) -> &FormatSpec
Returns the full FormatSpec.
Sourcepub fn align(&self) -> Align
pub fn align(&self) -> Align
Returns the effective alignment: the value from the format spec if one was
explicitly requested, otherwise the default set by Formatter::set_default_align.
Sourcepub fn fmt_type(&self) -> FmtType
pub fn fmt_type(&self) -> FmtType
Returns the format type (e.g. FmtType::LowerHex, FmtType::Debug).
Sourcepub fn set_default_align(&mut self, align: Align)
pub fn set_default_align(&mut self, align: Align)
Sets the default alignment used when none is specified in the format string.
Overrides the initial Left default. Call this before write!(f, ...) when
implementing a type that should right-align by default (e.g. a custom numeric type).