pub fn from_fn<F>(f: F) -> FromFn<F>where
F: Fn(&mut Formatter<'_>) -> Result<(), Error>,
Creates a type whose fmt::Debug and fmt::Display impls are forwarded to the provided closure.
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'");
© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/fmt/fn.from_fn.html