]> git.lizzy.rs Git - rust.git/commitdiff
collections: Avoid unstable code in examples for String
authorUlrik Sverdrup <root@localhost>
Tue, 19 May 2015 01:33:17 +0000 (03:33 +0200)
committerUlrik Sverdrup <root@localhost>
Tue, 19 May 2015 01:33:17 +0000 (03:33 +0200)
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.

src/liballoc/rc.rs
src/libcollections/string.rs

index 88c5c38172acad831be9c5c289bc124811def361..1e773b7f206bdcf6ed68046974e7f996bc45768b 100644 (file)
@@ -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<Owner> = 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
index 1f2443d9771800272e567b9103e45178444bdb04..7563bb76b52f803b7b5321a68bf6cd07e36de1ab 100644 (file)
@@ -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<u8>) -> 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<char> {
     /// # 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]);