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>