Function from_fn

#[must_use = "returns a type implementing Debug and Display, which do not have any effects unless they are used"]
pub const fn from_fn<F: Fn(&mut Formatter<'_>) -> Result>(f: F) -> FromFn<F>

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