Skip to content

Commit de3fcee

Browse files
committed
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.
1 parent 77cd5cc commit de3fcee

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/libcollections/string.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,19 @@ impl<'a> Deref<String> for DerefString<'a> {
880880
}
881881

882882
/// Convert a string slice to a wrapper type providing a `&String` reference.
883+
///
884+
/// # Examples
885+
///
886+
/// ```
887+
/// use std::string::as_string;
888+
///
889+
/// fn string_consumer(s: String) {
890+
/// assert_eq!(s, "foo".to_string());
891+
/// }
892+
///
893+
/// let string = as_string("foo").clone();
894+
/// string_consumer(string);
895+
/// ```
883896
#[experimental]
884897
pub fn as_string<'a>(x: &'a str) -> DerefString<'a> {
885898
DerefString { x: as_vec(x.as_bytes()) }

0 commit comments

Comments
 (0)