Function debug2::pprint_checked [−][src]
pub fn pprint_checked<T: Debug>(x: T) -> Result<String, Error>
Expand description
Pretty Print an item to a string, or return an error
use debug2::{pprint_checked, Debug, Formatter}; use std::fmt; struct Good; struct Bad; impl Debug for Good { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { f.debug_struct("Good").finish() } } impl Debug for Bad { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { Err(fmt::Error) } } assert!(pprint_checked(Good).is_ok()); assert!(pprint_checked(Bad).is_err());