Struct powerfmt::smart_display::Metadata
source · pub struct Metadata<'a, T>where
T: SmartDisplay + ?Sized,{ /* private fields */ }
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.
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.
impl<T> Copy for Metadata<'_, T>
Auto Trait Implementations§
impl<'a, T> Freeze for Metadata<'a, T>
impl<'a, T> RefUnwindSafe for Metadata<'a, T>
impl<'a, T> Send for Metadata<'a, T>
impl<'a, T> Sync for Metadata<'a, T>
impl<'a, T> Unpin for Metadata<'a, T>
impl<'a, T> UnwindSafe for Metadata<'a, T>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)