Skip to content

Commit 444a759

Browse files
committed
auto merge of #19628 : jbranchaud/rust/add-string-as-string-doctest, r=steveklabnik
2 parents ab1b1ae + de3fcee commit 444a759

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/libcollections/string.rs

+13
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,19 @@ impl<'a> Deref<String> for DerefString<'a> {
903903
}
904904

905905
/// Convert a string slice to a wrapper type providing a `&String` reference.
906+
///
907+
/// # Examples
908+
///
909+
/// ```
910+
/// use std::string::as_string;
911+
///
912+
/// fn string_consumer(s: String) {
913+
/// assert_eq!(s, "foo".to_string());
914+
/// }
915+
///
916+
/// let string = as_string("foo").clone();
917+
/// string_consumer(string);
918+
/// ```
906919
#[experimental]
907920
pub fn as_string<'a>(x: &'a str) -> DerefString<'a> {
908921
DerefString { x: as_vec(x.as_bytes()) }

0 commit comments

Comments
 (0)