Skip to content

Commit a9b6975

Browse files
committed
Write some docs for ToString
Part of #29376
1 parent 8bc43ed commit a9b6975

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/libcollections/string.rs

+20-2
Original file line numberDiff line numberDiff line change
@@ -1179,10 +1179,28 @@ impl PartialEq for ParseError {
11791179
#[stable(feature = "str_parse_error", since = "1.5.0")]
11801180
impl Eq for ParseError {}
11811181

1182-
/// A generic trait for converting a value to a string
1182+
/// A trait for converting a value to a `String`.
1183+
///
1184+
/// This trait is automatically implemented for any type which implements the
1185+
/// [`Display`] trait. As such, `ToString` shouldn't be implemented directly:
1186+
/// [`Display`] should be implemented instead, and you get the `ToString`
1187+
/// implementation for free.
1188+
///
1189+
/// [`Display`]: ../fmt/trait.Display.html
11831190
#[stable(feature = "rust1", since = "1.0.0")]
11841191
pub trait ToString {
1185-
/// Converts the value of `self` to an owned string
1192+
/// Converts the given value to a `String`.
1193+
///
1194+
/// # Examples
1195+
///
1196+
/// Basic usage:
1197+
///
1198+
/// ```
1199+
/// let i = 5;
1200+
/// let five = String::from("5");
1201+
///
1202+
/// assert_eq!(five, i.to_string());
1203+
/// ```
11861204
#[stable(feature = "rust1", since = "1.0.0")]
11871205
fn to_string(&self) -> String;
11881206
}

0 commit comments

Comments
 (0)