From: Ulrik Sverdrup Date: Tue, 19 May 2015 01:33:17 +0000 (+0200) Subject: collections: Avoid unstable code in examples for String X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=4e4374b7de0beec459f6d9db8e06f2cad0c969e7;p=rust.git collections: Avoid unstable code in examples for String Prefer String::from over from_str; String::from_str is unstable while String::from is stable. Promote the latter by using it in examples. Simply migrating unstable function to the closest alternative. --- diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 88c5c38172a..1e773b7f206 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -32,7 +32,7 @@ //! and have the `Owner` remain allocated as long as any `Gadget` points at it. //! //! ```rust -//! # #![feature(alloc, collections)] +//! # #![feature(alloc)] //! use std::rc::Rc; //! //! struct Owner { @@ -49,7 +49,7 @@ //! fn main() { //! // Create a reference counted Owner. //! let gadget_owner : Rc = Rc::new( -//! Owner { name: String::from_str("Gadget Man") } +//! Owner { name: String::from("Gadget Man") } //! ); //! //! // Create Gadgets belonging to gadget_owner. To increment the reference diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 1f2443d9771..7563bb76b52 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -121,9 +121,6 @@ pub fn from_str(_: &str) -> String { /// # Examples /// /// ``` - /// # #![feature(core)] - /// use std::str::Utf8Error; - /// /// let hello_vec = vec![104, 101, 108, 108, 111]; /// let s = String::from_utf8(hello_vec).unwrap(); /// assert_eq!(s, "hello"); @@ -346,8 +343,7 @@ pub unsafe fn from_utf8_unchecked(bytes: Vec) -> String { /// # Examples /// /// ``` - /// # #![feature(collections)] - /// let s = String::from_str("hello"); + /// let s = String::from("hello"); /// let bytes = s.into_bytes(); /// assert_eq!(bytes, [104, 101, 108, 108, 111]); /// ``` @@ -370,8 +366,7 @@ pub fn as_str(&self) -> &str { /// # Examples /// /// ``` - /// # #![feature(collections)] - /// let mut s = String::from_str("foo"); + /// let mut s = String::from("foo"); /// s.push_str("bar"); /// assert_eq!(s, "foobar"); /// ``` @@ -447,8 +442,7 @@ pub fn reserve_exact(&mut self, additional: usize) { /// # Examples /// /// ``` - /// # #![feature(collections)] - /// let mut s = String::from_str("foo"); + /// let mut s = String::from("foo"); /// s.reserve(100); /// assert!(s.capacity() >= 100); /// s.shrink_to_fit(); @@ -465,8 +459,7 @@ pub fn shrink_to_fit(&mut self) { /// # Examples /// /// ``` - /// # #![feature(collections)] - /// let mut s = String::from_str("abc"); + /// let mut s = String::from("abc"); /// s.push('1'); /// s.push('2'); /// s.push('3'); @@ -501,8 +494,7 @@ pub fn push(&mut self, ch: char) { /// # Examples /// /// ``` - /// # #![feature(collections)] - /// let s = String::from_str("hello"); + /// let s = String::from("hello"); /// let b: &[_] = &[104, 101, 108, 108, 111]; /// assert_eq!(s.as_bytes(), b); /// ``` @@ -522,8 +514,7 @@ pub fn as_bytes(&self) -> &[u8] { /// # Examples /// /// ``` - /// # #![feature(collections)] - /// let mut s = String::from_str("hello"); + /// let mut s = String::from("hello"); /// s.truncate(2); /// assert_eq!(s, "he"); /// ``` @@ -540,8 +531,7 @@ pub fn truncate(&mut self, new_len: usize) { /// # Examples /// /// ``` - /// # #![feature(collections)] - /// let mut s = String::from_str("foo"); + /// let mut s = String::from("foo"); /// assert_eq!(s.pop(), Some('o')); /// assert_eq!(s.pop(), Some('o')); /// assert_eq!(s.pop(), Some('f')); @@ -578,8 +568,7 @@ pub fn pop(&mut self) -> Option { /// # Examples /// /// ``` - /// # #![feature(collections)] - /// let mut s = String::from_str("foo"); + /// let mut s = String::from("foo"); /// assert_eq!(s.remove(0), 'f'); /// assert_eq!(s.remove(1), 'o'); /// assert_eq!(s.remove(0), 'o'); @@ -641,8 +630,7 @@ pub fn insert(&mut self, idx: usize, ch: char) { /// # Examples /// /// ``` - /// # #![feature(collections)] - /// let mut s = String::from_str("hello"); + /// let mut s = String::from("hello"); /// unsafe { /// let vec = s.as_mut_vec(); /// assert!(vec == &[104, 101, 108, 108, 111]);