Skip to content

Commit 91cdb0f

Browse files
authored
Rollup merge of #45869 - GuillaumeGomez:debug-doc, r=frewsxcv
Add missing example for Debug trait r? @rust-lang/docs
2 parents 65a0fb8 + 3d480b4 commit 91cdb0f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/libcore/fmt/mod.rs

+20
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,26 @@ impl<'a> Display for Arguments<'a> {
525525
#[lang = "debug_trait"]
526526
pub trait Debug {
527527
/// Formats the value using the given formatter.
528+
///
529+
/// # Examples
530+
///
531+
/// ```
532+
/// use std::fmt;
533+
///
534+
/// struct Position {
535+
/// longitude: f32,
536+
/// latitude: f32,
537+
/// }
538+
///
539+
/// impl fmt::Debug for Position {
540+
/// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
541+
/// write!(f, "({:?}, {:?})", self.longitude, self.latitude)
542+
/// }
543+
/// }
544+
///
545+
/// assert_eq!("(1.987, 2.983)".to_owned(),
546+
/// format!("{:?}", Position { longitude: 1.987, latitude: 2.983, }));
547+
/// ```
528548
#[stable(feature = "rust1", since = "1.0.0")]
529549
fn fmt(&self, f: &mut Formatter) -> Result;
530550
}

0 commit comments

Comments
 (0)