From de3fcee2dcc2458d9365951933e87b93bc41c32c Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Sun, 7 Dec 2014 17:47:00 -0600 Subject: [PATCH] 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. --- src/libcollections/string.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index fbb0bb5c4ce..aa344ccbffe 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -880,6 +880,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()) }