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 for StdIoWrite<W>where
W: Clone,
impl<W> Clone for StdIoWrite<W>where
W: Clone,
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 for StdIoWrite<W>where
W: Debug,
impl<W> Debug for StdIoWrite<W>where
W: Debug,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more