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.
This commit is contained in:
parent
4daa62a55f
commit
4e4374b7de
2 changed files with 11 additions and 23 deletions
|
@ -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
|
||||
|
|
|
@ -121,9 +121,6 @@ impl 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 @@ impl 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 @@ impl String {
|
|||
/// # 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 @@ impl String {
|
|||
/// # 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 @@ impl String {
|
|||
/// # 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 @@ impl String {
|
|||
/// # 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 @@ impl String {
|
|||
/// # 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 @@ impl String {
|
|||
/// # 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 @@ impl String {
|
|||
/// # 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 @@ impl String {
|
|||
/// # 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]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue