Struct StdIoWrite
pub struct StdIoWrite<W>(pub W);
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]",
);
# Ok::<(), Box<dyn std::error::Error>>(())
Fields
0: W
Trait Implementations
impl<W: Clone> Clone for StdIoWrite<W>
fn clone(&self) -> StdIoWrite<W>
impl<W: Debug> Debug for StdIoWrite<W>
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl<W: Write> Write for StdIoWrite<W>
fn write_str(&mut self, string: &str) -> Result<(), Error>
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> UnsafeUnpin for StdIoWrite<W>
where
W: UnsafeUnpin,
impl<W> UnwindSafe for StdIoWrite<W>
where
W: UnwindSafe,
Blanket Implementations
impl<T> Any for StdIoWrite<W>
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for StdIoWrite<W>
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for StdIoWrite<W>
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for StdIoWrite<W>
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for StdIoWrite<W>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for StdIoWrite<W>
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T, U> Into<U> for StdIoWrite<W>
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for StdIoWrite<W>
where
U: Into<T>,
type Error = Infallible;fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto<U> for StdIoWrite<W>
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>