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) -> StdFmtWrite<W>

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,

fn type_id(&self) -> TypeId

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

fn borrow(&self) -> &T

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

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

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

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

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

fn from(t: T) -> T

Returns the argument unchanged.

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

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

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

fn into(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<U> for StdFmtWrite<W> where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

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

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