about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorjbranchaud <jbranchaud@gmail.com>2014-12-07 17:47:00 -0600
committerjbranchaud <jbranchaud@gmail.com>2014-12-09 11:11:50 -0600
commitde3fcee2dcc2458d9365951933e87b93bc41c32c (patch)
treef8ae386208fd829fd141e274718d548e0146d80a /src
parent77cd5cc54eda4243614be32b893db512beab0f8e (diff)
downloadrust-de3fcee2dcc2458d9365951933e87b93bc41c32c.tar.gz
rust-de3fcee2dcc2458d9365951933e87b93bc41c32c.zip
Add a doctest for the std::string::as_string method.
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.
Diffstat (limited to 'src')
-rw-r--r--src/libcollections/string.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs
index fbb0bb5c4ce..aa344ccbffe 100644
--- a/src/libcollections/string.rs
+++ b/src/libcollections/string.rs
@@ -880,6 +880,19 @@ impl<'a> Deref<String> for DerefString<'a> {
 }
 
 /// 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()) }