Rollup merge of #45869 - GuillaumeGomez:debug-doc, r=frewsxcv

Add missing example for Debug trait

r? @rust-lang/docs
This commit is contained in:
kennytm 2017-11-10 17:07:07 +08:00 committed by GitHub
commit 91cdb0f9bd
1 changed files with 20 additions and 0 deletions

View File

@ -525,6 +525,26 @@ impl<'a> Display for Arguments<'a> {
#[lang = "debug_trait"]
pub trait Debug {
/// Formats the value using the given formatter.
///
/// # Examples
///
/// ```
/// use std::fmt;
///
/// struct Position {
/// longitude: f32,
/// latitude: f32,
/// }
///
/// impl fmt::Debug for Position {
/// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
/// write!(f, "({:?}, {:?})", self.longitude, self.latitude)
/// }
/// }
///
/// assert_eq!("(1.987, 2.983)".to_owned(),
/// format!("{:?}", Position { longitude: 1.987, latitude: 2.983, }));
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
fn fmt(&self, f: &mut Formatter) -> Result;
}