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_datetime(&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) -> Self

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,

impl<T> Borrow<T> for StdIoWrite<W> where T: ?Sized,

impl<T> BorrowMut<T> for StdIoWrite<W> where T: ?Sized,

impl<T> CloneToUninit for StdIoWrite<W> where T: Clone,

impl<T> From<T> for StdIoWrite<W>

impl<T> ToOwned for StdIoWrite<W> where T: Clone,

impl<T, U> Into<U> for StdIoWrite<W> where U: From<T>,

impl<T, U> TryFrom<U> for StdIoWrite<W> where U: Into<T>,

impl<T, U> TryInto<U> for StdIoWrite<W> where U: TryFrom<T>,