]> git.lizzy.rs Git - rust.git/commitdiff
Add a doctest for the std::string::as_string method.
authorjbranchaud <jbranchaud@gmail.com>
Sun, 7 Dec 2014 23:47:00 +0000 (17:47 -0600)
committerjbranchaud <jbranchaud@gmail.com>
Tue, 9 Dec 2014 17:11:50 +0000 (11:11 -0600)
Change Example to Examples.

Add a doctest that better demonstrates the utility of as_string.

Update the doctest example to use String instead of &String.

src/libcollections/string.rs

index fbb0bb5c4ce8673cf5fa71d3d34914a65d2ce024..aa344ccbffed2d9b8cffdeb6422a9949644b6bae 100644 (file)
@@ -880,6 +880,19 @@ fn deref<'b>(&'b self) -> &'b String {
 }
 
 /// Convert a string slice to a wrapper type providing a `&String` reference.
+///
+/// # Examples
+///
+/// ```
+/// use std::string::as_string;
+///
+/// fn string_consumer(s: String) {
+///     assert_eq!(s, "foo".to_string());
+/// }
+///
+/// let string = as_string("foo").clone();
+/// string_consumer(string);
+/// ```
 #[experimental]
 pub fn as_string<'a>(x: &'a str) -> DerefString<'a> {
     DerefString { x: as_vec(x.as_bytes()) }