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: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)