Skip to content

Commit 4e4374b

Browse files
author
Ulrik Sverdrup
committed
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.
1 parent 4daa62a commit 4e4374b

File tree

2 files changed

+11
-23
lines changed

2 files changed

+11
-23
lines changed

src/liballoc/rc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
//! and have the `Owner` remain allocated as long as any `Gadget` points at it.
3333
//!
3434
//! ```rust
35-
//! # #![feature(alloc, collections)]
35+
//! # #![feature(alloc)]
3636
//! use std::rc::Rc;
3737
//!
3838
//! struct Owner {
@@ -49,7 +49,7 @@
4949
//! fn main() {
5050
//! // Create a reference counted Owner.
5151
//! let gadget_owner : Rc<Owner> = Rc::new(
52-
//! Owner { name: String::from_str("Gadget Man") }
52+
//! Owner { name: String::from("Gadget Man") }
5353
//! );
5454
//!
5555
//! // Create Gadgets belonging to gadget_owner. To increment the reference

src/libcollections/string.rs

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,6 @@ impl String {
121121
/// # Examples
122122
///
123123
/// ```
124-
/// # #![feature(core)]
125-
/// use std::str::Utf8Error;
126-
///
127124
/// let hello_vec = vec![104, 101, 108, 108, 111];
128125
/// let s = String::from_utf8(hello_vec).unwrap();
129126
/// assert_eq!(s, "hello");
@@ -346,8 +343,7 @@ impl String {
346343
/// # Examples
347344
///
348345
/// ```
349-
/// # #![feature(collections)]
350-
/// let s = String::from_str("hello");
346+
/// let s = String::from("hello");
351347
/// let bytes = s.into_bytes();
352348
/// assert_eq!(bytes, [104, 101, 108, 108, 111]);
353349
/// ```
@@ -370,8 +366,7 @@ impl String {
370366
/// # Examples
371367
///
372368
/// ```
373-
/// # #![feature(collections)]
374-
/// let mut s = String::from_str("foo");
369+
/// let mut s = String::from("foo");
375370
/// s.push_str("bar");
376371
/// assert_eq!(s, "foobar");
377372
/// ```
@@ -447,8 +442,7 @@ impl String {
447442
/// # Examples
448443
///
449444
/// ```
450-
/// # #![feature(collections)]
451-
/// let mut s = String::from_str("foo");
445+
/// let mut s = String::from("foo");
452446
/// s.reserve(100);
453447
/// assert!(s.capacity() >= 100);
454448
/// s.shrink_to_fit();
@@ -465,8 +459,7 @@ impl String {
465459
/// # Examples
466460
///
467461
/// ```
468-
/// # #![feature(collections)]
469-
/// let mut s = String::from_str("abc");
462+
/// let mut s = String::from("abc");
470463
/// s.push('1');
471464
/// s.push('2');
472465
/// s.push('3');
@@ -501,8 +494,7 @@ impl String {
501494
/// # Examples
502495
///
503496
/// ```
504-
/// # #![feature(collections)]
505-
/// let s = String::from_str("hello");
497+
/// let s = String::from("hello");
506498
/// let b: &[_] = &[104, 101, 108, 108, 111];
507499
/// assert_eq!(s.as_bytes(), b);
508500
/// ```
@@ -522,8 +514,7 @@ impl String {
522514
/// # Examples
523515
///
524516
/// ```
525-
/// # #![feature(collections)]
526-
/// let mut s = String::from_str("hello");
517+
/// let mut s = String::from("hello");
527518
/// s.truncate(2);
528519
/// assert_eq!(s, "he");
529520
/// ```
@@ -540,8 +531,7 @@ impl String {
540531
/// # Examples
541532
///
542533
/// ```
543-
/// # #![feature(collections)]
544-
/// let mut s = String::from_str("foo");
534+
/// let mut s = String::from("foo");
545535
/// assert_eq!(s.pop(), Some('o'));
546536
/// assert_eq!(s.pop(), Some('o'));
547537
/// assert_eq!(s.pop(), Some('f'));
@@ -578,8 +568,7 @@ impl String {
578568
/// # Examples
579569
///
580570
/// ```
581-
/// # #![feature(collections)]
582-
/// let mut s = String::from_str("foo");
571+
/// let mut s = String::from("foo");
583572
/// assert_eq!(s.remove(0), 'f');
584573
/// assert_eq!(s.remove(1), 'o');
585574
/// assert_eq!(s.remove(0), 'o');
@@ -641,8 +630,7 @@ impl String {
641630
/// # Examples
642631
///
643632
/// ```
644-
/// # #![feature(collections)]
645-
/// let mut s = String::from_str("hello");
633+
/// let mut s = String::from("hello");
646634
/// unsafe {
647635
/// let vec = s.as_mut_vec();
648636
/// assert!(vec == &[104, 101, 108, 108, 111]);

0 commit comments

Comments
 (0)