from_fn

Function from_fn 

1.93.0 · Source
pub 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'");
Morty Proxy This is a proxified and sanitized view of the page, visit original site.