powerfmt::smart_display

Struct 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,

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 u8)

🔬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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.