Skip to content

Commit 42f7af5

Browse files
author
Ulrik Sverdrup
committed
collections: Improve example for as_string
1 parent f191f92 commit 42f7af5

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/libcollections/string.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -951,12 +951,13 @@ impl<'a> Deref for DerefString<'a> {
951951
/// # #![feature(collections)]
952952
/// use std::string::as_string;
953953
///
954-
/// fn string_consumer(s: String) {
955-
/// assert_eq!(s, "foo".to_string());
954+
/// // Let's pretend we have a function that requires &String
955+
/// fn string_consumer(s: &String) {
956+
/// assert_eq!(s, "foo");
956957
/// }
957958
///
958-
/// let string = as_string("foo").clone();
959-
/// string_consumer(string);
959+
/// // Provide a &String from a &str without allocating
960+
/// string_consumer(&as_string("foo"));
960961
/// ```
961962
#[unstable(feature = "collections")]
962963
pub fn as_string<'a>(x: &'a str) -> DerefString<'a> {

0 commit comments

Comments
 (0)