Struct powerfmt::smart_display::Metadata
source · pub struct Metadata<'a, T>where
T: SmartDisplay + ?Sized,{
unpadded_width: usize,
metadata: T::Metadata,
_value: PhantomData<&'a T>,
}
Expand description
Information used to format a value. This is returned by SmartDisplay::metadata
.
This type is generic over any user-provided type. This allows the author to store any
information that is needed. For example, a type’s implementation of SmartDisplay
may need
to calculate something before knowing its width. This calculation can be performed, with the
result being stored in the custom metadata type.
Note that Metadata
always contains the width of the type. Authors do not need to store this
information in their custom metadata type.
Generally speaking, a type should be able to be formatted using only its metadata, fields, and the formatter. Any other information should be stored in the metadata type.
Fields§
§unpadded_width: usize
§metadata: T::Metadata
§_value: PhantomData<&'a T>
Implementations§
source§impl<'a, T> Metadata<'a, T>where
T: SmartDisplay + ?Sized,
impl<'a, T> Metadata<'a, T>where
T: SmartDisplay + ?Sized,
sourcepub const fn new(
unpadded_width: usize,
_value: &T,
metadata: T::Metadata,
) -> Self
pub const fn new( unpadded_width: usize, _value: &T, metadata: T::Metadata, ) -> Self
Creates a new Metadata
with the given width and metadata. While the width should be
exact, this is not a requirement for soundness.
sourcepub fn reuse<'b, U>(self) -> Metadata<'b, U>
pub fn reuse<'b, U>(self) -> Metadata<'b, U>
Reuse the metadata for another type. This is useful when implementing SmartDisplay
for a
type that wraps another type. Both type’s metadata type must be the same.
sourcepub const fn unpadded_width(&self) -> usize
pub const fn unpadded_width(&self) -> usize
Obtain the width of the value before padding.
sourcepub fn padded_width(&self, f: FormatterOptions) -> usize
pub fn padded_width(&self, f: FormatterOptions) -> usize
Obtain the width of the value after padding.
source§impl Metadata<'_, Infallible>
impl Metadata<'_, Infallible>
sourcepub fn unpadded_width_of<T>(value: T, f: FormatterOptions) -> usizewhere
T: SmartDisplay,
pub fn unpadded_width_of<T>(value: T, f: FormatterOptions) -> usizewhere
T: SmartDisplay,
Obtain the width of the value before padding, given the formatter options.
sourcepub fn padded_width_of<T>(value: T, f: FormatterOptions) -> usizewhere
T: SmartDisplay,
pub fn padded_width_of<T>(value: T, f: FormatterOptions) -> usizewhere
T: SmartDisplay,
Obtain the width of the value after padding, given the formatter options.
Trait Implementations§
source§impl<T> Deref for Metadata<'_, T>where
T: SmartDisplay + ?Sized,
impl<T> Deref for Metadata<'_, T>where
T: SmartDisplay + ?Sized,
Permit using Metadata
as a smart pointer to the user-provided metadata.