pub struct StdIoWrite<W>(pub W);
Expand description
An adapter for using std::io::Write
implementations with fmt::Write
.
This is useful when one wants to format a datetime or span directly
to something with a std::io::Write
trait implementation but not a
fmt::Write
implementation.
§Example
use std::{fs::File, io::{BufWriter, Write}, path::Path};
use jiff::{civil::date, fmt::{StdIoWrite, temporal::DateTimePrinter}};
let zdt = date(2024, 6, 15).at(7, 0, 0, 0).in_tz("America/New_York")?;
let path = Path::new("/tmp/output");
let mut file = BufWriter::new(File::create(path)?);
DateTimePrinter::new().print_zoned(&zdt, StdIoWrite(&mut file)).unwrap();
file.flush()?;
assert_eq!(
std::fs::read_to_string(path)?,
"2024-06-15T07:00:00-04:00[America/New_York]",
);
Tuple Fields§
§0: W
Trait Implementations§
Source§impl<W: Clone> Clone for StdIoWrite<W>
impl<W: Clone> Clone for StdIoWrite<W>
Source§fn clone(&self) -> StdIoWrite<W>
fn clone(&self) -> StdIoWrite<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 StdIoWrite<W>
impl<W: Debug> Debug for StdIoWrite<W>
Auto Trait Implementations§
impl<W> Freeze for StdIoWrite<W>where
W: Freeze,
impl<W> RefUnwindSafe for StdIoWrite<W>where
W: RefUnwindSafe,
impl<W> Send for StdIoWrite<W>where
W: Send,
impl<W> Sync for StdIoWrite<W>where
W: Sync,
impl<W> Unpin for StdIoWrite<W>where
W: Unpin,
impl<W> UnwindSafe for StdIoWrite<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