diff options
| author | jbranchaud <jbranchaud@gmail.com> | 2014-12-07 17:47:00 -0600 |
|---|---|---|
| committer | jbranchaud <jbranchaud@gmail.com> | 2014-12-09 11:11:50 -0600 |
| commit | de3fcee2dcc2458d9365951933e87b93bc41c32c (patch) | |
| tree | f8ae386208fd829fd141e274718d548e0146d80a /src | |
| parent | 77cd5cc54eda4243614be32b893db512beab0f8e (diff) | |
| download | rust-de3fcee2dcc2458d9365951933e87b93bc41c32c.tar.gz rust-de3fcee2dcc2458d9365951933e87b93bc41c32c.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcollections/string.rs | 13 |
1 files changed, 13 insertions, 0 deletions
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 @@ impl<'a> Deref<String> for DerefString<'a> { } /// 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()) } |
