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,

source

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.

source

pub fn reuse<'b, U>(self) -> Metadata<'b, U>
where U: SmartDisplay<Metadata = T::Metadata> + ?Sized, 'a: 'b,

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.

source

pub const fn unpadded_width(&self) -> usize

Obtain the width of the value before padding.

source

pub fn padded_width(&self, f: FormatterOptions) -> usize

Obtain the width of the value after padding.

source§

impl Metadata<'_, Infallible>

source

pub fn unpadded_width_of<T>(value: T, f: FormatterOptions) -> usize
where T: SmartDisplay,

Obtain the width of the value before padding, given the formatter options.

source

pub fn padded_width_of<T>(value: T, f: FormatterOptions) -> usize
where T: SmartDisplay,

Obtain the width of the value after padding, given the formatter options.

Trait Implementations§

source§

impl<T> Clone for Metadata<'_, T>
where T: SmartDisplay, T::Metadata: Clone,

source§

fn clone(&self) -> Self

Returns a copy 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<T> Debug for Metadata<'_, T>
where T: SmartDisplay, T::Metadata: Debug,

source§

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

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

impl<T> Deref for Metadata<'_, T>
where T: SmartDisplay + ?Sized,

Permit using Metadata as a smart pointer to the user-provided metadata.

source§

type Target = <T as SmartDisplay>::Metadata

The resulting type after dereferencing.
source§

fn deref(&self) -> &T::Metadata

Dereferences the value.
source§

impl<T> Copy for Metadata<'_, T>
where T: SmartDisplay, T::Metadata: Copy,

Auto Trait Implementations§

§

impl<'a, T> Freeze for Metadata<'a, T>
where <T as SmartDisplay>::Metadata: Freeze, T: ?Sized,

§

impl<'a, T> RefUnwindSafe for Metadata<'a, T>

§

impl<'a, T> Send for Metadata<'a, T>
where <T as SmartDisplay>::Metadata: Send, T: Sync + ?Sized,

§

impl<'a, T> Sync for Metadata<'a, T>
where <T as SmartDisplay>::Metadata: Sync, T: Sync + ?Sized,

§

impl<'a, T> Unpin for Metadata<'a, T>
where <T as SmartDisplay>::Metadata: Unpin, T: ?Sized,

§

impl<'a, T> UnwindSafe for Metadata<'a, T>

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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, 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.