pub struct StdFmtWrite<W>(pub W);
Expand description
An adapter for using std::fmt::Write
implementations with fmt::Write
.
This is useful when one wants to format a datetime or span directly
to something with a std::fmt::Write
trait implementation but not a
fmt::Write
implementation.
(Despite using Std
in this name, this type is available in core
-only
configurations.)
§Example
This example shows the std::fmt::Display
trait implementation for
civil::DateTime
(but using a wrapper type).
use jiff::{civil::DateTime, fmt::{temporal::DateTimePrinter, StdFmtWrite}};
struct MyDateTime(DateTime);
impl std::fmt::Display for MyDateTime {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
static P: DateTimePrinter = DateTimePrinter::new();
P.print_datetime(&self.0, StdFmtWrite(f))
.map_err(|_| std::fmt::Error)
}
}
let dt = MyDateTime(DateTime::constant(2024, 6, 15, 17, 30, 0, 0));
assert_eq!(dt.to_string(), "2024-06-15T17:30:00");
Tuple Fields§
§0: W
Trait Implementations§
Source§impl<W: Clone> Clone for StdFmtWrite<W>
impl<W: Clone> Clone for StdFmtWrite<W>
Source§fn clone(&self) -> StdFmtWrite<W>
fn clone(&self) -> StdFmtWrite<W>
Returns a copy 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<W: Debug> Debug for StdFmtWrite<W>
impl<W: Debug> Debug for StdFmtWrite<W>
Source§impl<W: Write> Write for StdFmtWrite<W>
impl<W: Write> Write for StdFmtWrite<W>
Auto Trait Implementations§
impl<W> Freeze for StdFmtWrite<W>where
W: Freeze,
impl<W> RefUnwindSafe for StdFmtWrite<W>where
W: RefUnwindSafe,
impl<W> Send for StdFmtWrite<W>where
W: Send,
impl<W> Sync for StdFmtWrite<W>where
W: Sync,
impl<W> Unpin for StdFmtWrite<W>where
W: Unpin,
impl<W> UnwindSafe for StdFmtWrite<W>where
W: UnwindSafe,
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