/// Finishes output and returns any error encountered. /// /// # Example /// /// ``` /// use core::fmt; /// use derive_more::__private::debug_tuple; /// /// struct Foo(i32, String); /// /// impl fmt::Debug for Foo { /// fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { /// debug_tuple(fmt, "Foo") /// .field(&self.0) /// .field(&self.1) /// .finish() // You need to call it to "finish" the /// // tuple formatting. /// } /// } /// /// assert_eq!( /// format!("{:?}", Foo(10, "Hello World".to_string())), /// "Foo(10, \"Hello World\")", /// ); /// ``` pubfn finish(&mutself) -> Result { ifself.fields > 0 { self.result = self.result.and_then(|_| { ifself.fields == 1 && self.empty_name && !self.is_pretty() { self.fmt.write_str(",")?;
} self.fmt.write_str(")")
});
} self.result
}
/// Marks the struct as non-exhaustive, indicating to the reader that there are some other /// fields that are not shown in the debug representation, and finishes output, returning any /// error encountered. /// /// # Example /// /// ```rust /// use core::fmt; /// use derive_more::__private::debug_tuple; /// /// struct Bar(i32, f32); /// /// impl fmt::Debug for Bar { /// fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { /// debug_tuple(fmt, "Bar") /// .field(&self.0) /// .finish_non_exhaustive() // Show that some other field(s) exist. /// } /// } /// /// assert_eq!(format!("{:?}", Bar(10, 1.0)), "Bar(10, ..)"); /// ``` pubfn finish_non_exhaustive(&mutself) -> Result { self.result = self.result.and_then(|_| { ifself.fields > 0 { ifself.is_pretty() { letmut padded_formatter = Padded::new(self.fmt);
padded_formatter.write_str("..\n")?; self.fmt.write_str(")")
} else { self.fmt.write_str(", ..)")
}
} else { self.fmt.write_str("(..)")
}
}); self.result
}
impl<'a, 'b> Write for Padded<'a, 'b> { fn write_str(&mutself, s: &str) -> Result { for s in s.split_inclusive('\n') { ifself.on_newline { self.formatter.write_str(" ")?;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.