]> git.lizzy.rs Git - rust.git/commitdiff
auto merge of #19628 : jbranchaud/rust/add-string-as-string-doctest, r=steveklabnik
authorbors <bors@rust-lang.org>
Wed, 10 Dec 2014 06:46:16 +0000 (06:46 +0000)
committerbors <bors@rust-lang.org>
Wed, 10 Dec 2014 06:46:16 +0000 (06:46 +0000)
src/libcollections/string.rs

index 6943ec69359f8af6d28cfc2eb5104e4133cb5b51..0f86b5ffa684a2d8a185ee637ff6bfc675d9ec2b 100644 (file)
@@ -903,6 +903,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()) }