Struct Metadata
pub struct Metadata<'a, T>
where
T: SmartDisplay + ?Sized, { /* private fields */ }
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
impl Metadata<'_, Infallible>
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.
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.
impl<'a, T> Metadata<'a, T>
where
T: SmartDisplay + ?Sized,
const fn new(unpadded_width: usize, _value: &T, metadata: T::Metadata) -> SelfCreates a new
Metadatawith the given width and metadata. While the width should be exact, this is not a requirement for soundness.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
SmartDisplayfor a type that wraps another type. Both type's metadata type must be the same.const fn unpadded_width(&self) -> usizeObtain the width of the value before padding.
fn padded_width(&self, f: FormatterOptions) -> usizeObtain the width of the value after padding.
Trait Implementations
impl<T> Clone for Metadata<'_, T>
where
T: SmartDisplay,
T::Metadata: Clone,
fn clone(&self) -> Self
impl<T> Copy for Metadata<'_, T>
where
T: SmartDisplay,
T::Metadata: Copy,
impl<T> Debug for Metadata<'_, T>
where
T: SmartDisplay,
T::Metadata: Debug,
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl<T> Deref for Metadata<'_, T>
where
T: SmartDisplay + ?Sized,
type Target = <T as SmartDisplay>::Metadata;fn deref(&self) -> &T::Metadata
Auto Trait Implementations
impl<'a, T> Freeze for Metadata<'a, T>
where
<T as SmartDisplay>::Metadata: Freeze,
PhantomData<&'a T>: Freeze,
T: ?Sized,
impl<'a, T> RefUnwindSafe for Metadata<'a, T>
where
<T as SmartDisplay>::Metadata: RefUnwindSafe,
PhantomData<&'a T>: RefUnwindSafe,
T: ?Sized,
impl<'a, T> Send for Metadata<'a, T>
where
<T as SmartDisplay>::Metadata: Send,
PhantomData<&'a T>: Send,
T: ?Sized,
impl<'a, T> Sync for Metadata<'a, T>
where
<T as SmartDisplay>::Metadata: Sync,
PhantomData<&'a T>: Sync,
T: ?Sized,
impl<'a, T> Unpin for Metadata<'a, T>
where
<T as SmartDisplay>::Metadata: Unpin,
PhantomData<&'a T>: Unpin,
T: ?Sized,
impl<'a, T> UnsafeUnpin for Metadata<'a, T>
where
<T as SmartDisplay>::Metadata: UnsafeUnpin,
PhantomData<&'a T>: UnsafeUnpin,
T: ?Sized,
impl<'a, T> UnwindSafe for Metadata<'a, T>
where
<T as SmartDisplay>::Metadata: UnwindSafe,
PhantomData<&'a T>: UnwindSafe,
T: ?Sized,
Blanket Implementations
impl<P, T> Receiver for Metadata<'a, T>
where
P: Deref<Target = T> + ?Sized,
T: ?Sized,
type Target = T;
impl<T> Any for Metadata<'a, T>
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for Metadata<'a, T>
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for Metadata<'a, T>
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for Metadata<'a, T>
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for Metadata<'a, T>
fn from(t: T) -> TReturns the argument unchanged.
impl<T, U> Into<U> for Metadata<'a, T>
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for Metadata<'a, T>
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for Metadata<'a, T>
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>