Skip to content

Commit a5a3981

Browse files
Add missing example for Display::fmt
1 parent 11bc48a commit a5a3981

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/libcore/fmt/mod.rs

+20-1
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,26 @@ pub trait Debug {
529529
#[stable(feature = "rust1", since = "1.0.0")]
530530
pub trait Display {
531531
/// Formats the value using the given formatter.
532+
///
533+
/// # Examples
534+
///
535+
/// ```
536+
/// use std::fmt;
537+
///
538+
/// struct Position {
539+
/// longitude: f32,
540+
/// latitude: f32,
541+
/// }
542+
///
543+
/// impl fmt::Display for Position {
544+
/// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
545+
/// write!(f, "({}, {})", self.longitude, self.latitude)
546+
/// }
547+
/// }
548+
///
549+
/// assert_eq!("(1.987, 2.983)".to_owned(),
550+
/// format!("{}", Position { longitude: 1.987, latitude: 2.983, }));
551+
/// ```
532552
#[stable(feature = "rust1", since = "1.0.0")]
533553
fn fmt(&self, f: &mut Formatter) -> Result;
534554
}
@@ -930,7 +950,6 @@ pub fn write(output: &mut Write, args: Arguments) -> Result {
930950
}
931951

932952
impl<'a> Formatter<'a> {
933-
934953
// First up is the collection of functions used to execute a format string
935954
// at runtime. This consumes all of the compile-time statics generated by
936955
// the format! syntax extension.

0 commit comments

Comments
 (0)