Function from_fn
1.93.0 (const: 1.95.0) · Source pub const fn from_fn<F: Fn(&mut Formatter<'_>) -> Result>(f: F) -> FromFn<F>
This item is validated for IEC 61508 (SIL 2) and ISO 26262 (ASIL B).
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'");