Struct StdFmtWrite

struct StdFmtWrite<W>(2136)

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");

Implementations

impl<T> Any for StdFmtWrite<W>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for StdFmtWrite<W>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for StdFmtWrite<W>

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> CloneToUninit for StdFmtWrite<W>

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> From for StdFmtWrite<W>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for StdFmtWrite<W>

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T, U> Into for StdFmtWrite<W>

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for StdFmtWrite<W>

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for StdFmtWrite<W>

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>

impl<W> Freeze for StdFmtWrite<W>

impl<W> RefUnwindSafe for StdFmtWrite<W>

impl<W> Send for StdFmtWrite<W>

impl<W> Sync for StdFmtWrite<W>

impl<W> Unpin for StdFmtWrite<W>

impl<W> UnwindSafe for StdFmtWrite<W>

impl<W: $crate::clone::Clone> Clone for StdFmtWrite<W>

fn clone(self: &Self) -> StdFmtWrite<W>

impl<W: $crate::fmt::Debug> Debug for StdFmtWrite<W>

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

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

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

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

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