Skip to main content

## from_fn

# Function from_fn

1.93.0 (const: 1.95.0) · Source

    pub const fn from_fn<F>(f: F) -> FromFn<F>where
        F: Fn(&mut Formatter<'_>) -> Result<(), Error>,

Expand description

Creates a type whose `fmt::Debug` and `fmt::Display` impls are forwarded to the provided closure.

## §Examples

    use std::fmt;

    let value = 'a';
    assert_eq!(format!("{}", value), "a");
    assert_eq!(format!("{:?}", value), "'a'");

    let wrapped = fmt::from_fn(|f| write!(f, "{value:?}"));
    assert_eq!(format!("{}", wrapped), "'a'");
    assert_eq!(format!("{:?}", wrapped), "'a'");