pub struct DisplayContext<T> {
pub display: fn(&T, &mut Formatter<'_>) -> Result<(), Error>,
}Expand description
A context providing a custom display function.
When used with WithContext, implements Display by dispatching
through the stored format function.
§Examples
use context_trait::{WithContext, DisplayContext};
let ctx = DisplayContext {
display: |v: &(i32, i32), f: &mut std::fmt::Formatter| {
write!(f, "({}, {})", v.0, v.1)
},
};
let w = WithContext { inner: (1, 2), ctx };
assert_eq!(format!("{w}"), "(1, 2)");Fields§
§display: fn(&T, &mut Formatter<'_>) -> Result<(), Error>The display function.
Trait Implementations§
Source§impl<T> Clone for DisplayContext<T>
impl<T> Clone for DisplayContext<T>
Source§fn clone(&self) -> DisplayContext<T>
fn clone(&self) -> DisplayContext<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T> Debug for DisplayContext<T>
impl<T> Debug for DisplayContext<T>
impl<T> Copy for DisplayContext<T>
Auto Trait Implementations§
impl<T> Freeze for DisplayContext<T>
impl<T> RefUnwindSafe for DisplayContext<T>
impl<T> Send for DisplayContext<T>
impl<T> Sync for DisplayContext<T>
impl<T> Unpin for DisplayContext<T>
impl<T> UnsafeUnpin for DisplayContext<T>
impl<T> UnwindSafe for DisplayContext<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
Mutably borrows from an owned value. Read more