Struct StdFmtWrite
pub struct StdFmtWrite<W>(pub W);
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");
Fields
0: W
Trait Implementations
impl<W: Clone> Clone for StdFmtWrite<W>
fn clone(&self) -> Self
impl<W: Debug> Debug for StdFmtWrite<W>
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl<W: Write> Write for StdFmtWrite<W>
fn write_str(&mut self, string: &str) -> Result<(), Error>
impl<W: Write> Write for StdFmtWrite<W>
fn write_str(&mut self, string: &str) -> Result<(), Error>