Struct StdFmtWrite

pub struct StdFmtWrite<W>(pub W);

An adapter for using std::fmt::Write implementations with fmt::Write.

This is useful when one wants to format a datetime or span directly to something with a std::fmt::Write trait implementation but not a fmt::Write implementation.

(Despite using Std in this name, this type is available in core-only configurations.)

Example

This example shows the std::fmt::Display trait implementation for civil::DateTime (but using a wrapper type).

use jiff::{civil::DateTime, fmt::{temporal::DateTimePrinter, StdFmtWrite}};

struct MyDateTime(DateTime);

impl std::fmt::Display for MyDateTime {
    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {

        static P: DateTimePrinter = DateTimePrinter::new();
        P.print_datetime(&self.0, StdFmtWrite(f))
            .map_err(|_| std::fmt::Error)
    }
}

let dt = MyDateTime(DateTime::constant(2024, 6, 15, 17, 30, 0, 0));
assert_eq!(dt.to_string(), "2024-06-15T17:30:00");

Fields

0: W

Trait Implementations

impl<W: Clone> Clone for StdFmtWrite<W>

fn clone(&self) -> Self

impl<W: Debug> Debug for StdFmtWrite<W>

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl<W: Write> Write for StdFmtWrite<W>

fn write_str(&mut self, string: &str) -> Result<(), Error>

impl<W: Write> Write for StdFmtWrite<W>

fn write_str(&mut self, string: &str) -> Result<(), Error>

Auto Trait Implementations

impl<W> Freeze for StdFmtWrite<W> where W: Freeze,

impl<W> RefUnwindSafe for StdFmtWrite<W> where W: RefUnwindSafe,

impl<W> Send for StdFmtWrite<W> where W: Send,

impl<W> Sync for StdFmtWrite<W> where W: Sync,

impl<W> Unpin for StdFmtWrite<W> where W: Unpin,

impl<W> UnsafeUnpin for StdFmtWrite<W> where W: UnsafeUnpin,

impl<W> UnwindSafe for StdFmtWrite<W> where W: UnwindSafe,

Blanket Implementations

impl<T> Any for StdFmtWrite<W> where T: 'static + ?Sized,

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

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

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

impl<T> From<T> for StdFmtWrite<W>

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

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

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

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