We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f191f92 commit 42f7af5Copy full SHA for 42f7af5
src/libcollections/string.rs
@@ -951,12 +951,13 @@ impl<'a> Deref for DerefString<'a> {
951
/// # #![feature(collections)]
952
/// use std::string::as_string;
953
///
954
-/// fn string_consumer(s: String) {
955
-/// assert_eq!(s, "foo".to_string());
+/// // Let's pretend we have a function that requires &String
+/// fn string_consumer(s: &String) {
956
+/// assert_eq!(s, "foo");
957
/// }
958
-/// let string = as_string("foo").clone();
959
-/// string_consumer(string);
+/// // Provide a &String from a &str without allocating
960
+/// string_consumer(&as_string("foo"));
961
/// ```
962
#[unstable(feature = "collections")]
963
pub fn as_string<'a>(x: &'a str) -> DerefString<'a> {
0 commit comments