From 227d30414ca88aad644ea4fde2c33852b1fd6ad9 Mon Sep 17 00:00:00 2001 From: Ulrik Sverdrup Date: Tue, 24 Mar 2015 19:37:52 +0100 Subject: [PATCH 1/3] std: Update docs for removal of ReadExt, WriteExt --- src/libstd/io/mod.rs | 30 +++++++++++++++--------------- src/libstd/io/prelude.rs | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 39c718c96b38a..28ac23571d0d0 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -647,14 +647,14 @@ pub trait BufRead: Read { /// A `Write` adaptor which will write data to multiple locations. /// -/// For more information, see `WriteExt::broadcast`. -#[unstable(feature = "io", reason = "awaiting stability of WriteExt::broadcast")] +/// For more information, see `Write::broadcast`. +#[unstable(feature = "io", reason = "awaiting stability of Write::broadcast")] pub struct Broadcast { first: T, second: U, } -#[unstable(feature = "io", reason = "awaiting stability of WriteExt::broadcast")] +#[unstable(feature = "io", reason = "awaiting stability of Write::broadcast")] impl Write for Broadcast { fn write(&mut self, data: &[u8]) -> Result { let n = try!(self.first.write(data)); @@ -670,7 +670,7 @@ impl Write for Broadcast { /// Adaptor to chain together two instances of `Read`. /// -/// For more information, see `ReadExt::chain`. +/// For more information, see `Read::chain`. #[stable(feature = "rust1", since = "1.0.0")] pub struct Chain { first: T, @@ -693,7 +693,7 @@ impl Read for Chain { /// Reader adaptor which limits the bytes read from an underlying reader. /// -/// For more information, see `ReadExt::take`. +/// For more information, see `Read::take`. #[stable(feature = "rust1", since = "1.0.0")] pub struct Take { inner: T, @@ -746,14 +746,14 @@ impl BufRead for Take { /// An adaptor which will emit all read data to a specified writer as well. /// -/// For more information see `ReadExt::tee` -#[unstable(feature = "io", reason = "awaiting stability of ReadExt::tee")] +/// For more information see `Read::tee` +#[unstable(feature = "io", reason = "awaiting stability of Read::tee")] pub struct Tee { reader: R, writer: W, } -#[unstable(feature = "io", reason = "awaiting stability of ReadExt::tee")] +#[unstable(feature = "io", reason = "awaiting stability of Read::tee")] impl Read for Tee { fn read(&mut self, buf: &mut [u8]) -> Result { let n = try!(self.reader.read(buf)); @@ -765,7 +765,7 @@ impl Read for Tee { /// A bridge from implementations of `Read` to an `Iterator` of `u8`. /// -/// See `ReadExt::bytes` for more information. +/// See `Read::bytes` for more information. #[stable(feature = "rust1", since = "1.0.0")] pub struct Bytes { inner: R, @@ -787,8 +787,8 @@ impl Iterator for Bytes { /// A bridge from implementations of `Read` to an `Iterator` of `char`. /// -/// See `ReadExt::chars` for more information. -#[unstable(feature = "io", reason = "awaiting stability of ReadExt::chars")] +/// See `Read::chars` for more information. +#[unstable(feature = "io", reason = "awaiting stability of Read::chars")] pub struct Chars { inner: R, } @@ -796,7 +796,7 @@ pub struct Chars { /// An enumeration of possible errors that can be generated from the `Chars` /// adapter. #[derive(PartialEq, Clone, Debug)] -#[unstable(feature = "io", reason = "awaiting stability of ReadExt::chars")] +#[unstable(feature = "io", reason = "awaiting stability of Read::chars")] pub enum CharsError { /// Variant representing that the underlying stream was read successfully /// but it did not contain valid utf8 data. @@ -806,7 +806,7 @@ pub enum CharsError { Other(Error), } -#[unstable(feature = "io", reason = "awaiting stability of ReadExt::chars")] +#[unstable(feature = "io", reason = "awaiting stability of Read::chars")] impl Iterator for Chars { type Item = result::Result; @@ -838,7 +838,7 @@ impl Iterator for Chars { } } -#[unstable(feature = "io", reason = "awaiting stability of ReadExt::chars")] +#[unstable(feature = "io", reason = "awaiting stability of Read::chars")] impl std_error::Error for CharsError { fn description(&self) -> &str { match *self { @@ -854,7 +854,7 @@ impl std_error::Error for CharsError { } } -#[unstable(feature = "io", reason = "awaiting stability of ReadExt::chars")] +#[unstable(feature = "io", reason = "awaiting stability of Read::chars")] impl fmt::Display for CharsError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { diff --git a/src/libstd/io/prelude.rs b/src/libstd/io/prelude.rs index a2ceacbe1f897..333ae8f26a0d7 100644 --- a/src/libstd/io/prelude.rs +++ b/src/libstd/io/prelude.rs @@ -18,7 +18,7 @@ //! ``` //! //! This module contains reexports of many core I/O traits such as `Read`, -//! `Write`, `ReadExt`, and `WriteExt`. Structures and functions are not +//! `Write` and `BufRead`. Structures and functions are not //! contained in this module. #![stable(feature = "rust1", since = "1.0.0")] From 00e14f16225fcf529b6d8a20c4c000d803064ec8 Mon Sep 17 00:00:00 2001 From: Ulrik Sverdrup Date: Tue, 24 Mar 2015 19:57:49 +0100 Subject: [PATCH 2/3] core: Update docs for StrExt demotion in libstd Main access point of .split() and other similar methods are not using the StrExt trait anymore, so update the libcore docs to reflect this (because these docs are visible in libstd API documentation). --- src/libcollections/str.rs | 2 +- src/libcore/str/mod.rs | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index ca2786e843e97..aaa73badcac99 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -19,7 +19,7 @@ //! are owned elsewhere. //! //! Basic operations are implemented directly by the compiler, but more advanced -//! operations are defined on the [`StrExt`](trait.StrExt.html) trait. +//! operations are defined as methods on the `str` type. //! //! # Examples //! diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index b7285d30a7309..5c4d8427ea2fc 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -164,8 +164,7 @@ impl FromStr for bool { /// assert!(::from_str("not even a boolean").is_err()); /// ``` /// - /// Note, in many cases, the StrExt::parse() which is based on - /// this FromStr::from_str() is more proper. + /// Note, in many cases, the `.parse()` method on `str` is more proper. /// /// ``` /// assert_eq!("true".parse(), Ok(true)); @@ -530,7 +529,7 @@ impl<'a> DoubleEndedIterator for CharIndices<'a> { /// External iterator for a string's bytes. /// Use with the `std::iter` module. /// -/// Created with `StrExt::bytes` +/// Created with `str::bytes` #[stable(feature = "rust1", since = "1.0.0")] #[derive(Clone)] pub struct Bytes<'a>(Map, BytesDeref>); @@ -1461,27 +1460,27 @@ impl<'a, S: ?Sized> Str for &'a S where S: Str { fn as_slice(&self) -> &str { Str::as_slice(*self) } } -/// Return type of `StrExt::split` +/// Return type of `str::split` #[stable(feature = "rust1", since = "1.0.0")] pub struct Split<'a, P: Pattern<'a>>(CharSplits<'a, P>); delegate_iter!{pattern &'a str : Split<'a, P>} -/// Return type of `StrExt::split_terminator` +/// Return type of `str::split_terminator` #[stable(feature = "rust1", since = "1.0.0")] pub struct SplitTerminator<'a, P: Pattern<'a>>(CharSplits<'a, P>); delegate_iter!{pattern &'a str : SplitTerminator<'a, P>} -/// Return type of `StrExt::splitn` +/// Return type of `str::splitn` #[stable(feature = "rust1", since = "1.0.0")] pub struct SplitN<'a, P: Pattern<'a>>(CharSplitsN<'a, P>); delegate_iter!{pattern forward &'a str : SplitN<'a, P>} -/// Return type of `StrExt::rsplit` +/// Return type of `str::rsplit` #[stable(feature = "rust1", since = "1.0.0")] pub struct RSplit<'a, P: Pattern<'a>>(RCharSplits<'a, P>); delegate_iter!{pattern reverse &'a str : RSplit<'a, P>} -/// Return type of `StrExt::rsplitn` +/// Return type of `str::rsplitn` #[stable(feature = "rust1", since = "1.0.0")] pub struct RSplitN<'a, P: Pattern<'a>>(RCharSplitsN<'a, P>); delegate_iter!{pattern reverse &'a str : RSplitN<'a, P>} From 547a48e1936ec7f369bf338fd7f5048f47265868 Mon Sep 17 00:00:00 2001 From: Ulrik Sverdrup Date: Tue, 24 Mar 2015 19:47:00 +0100 Subject: [PATCH 3/3] collections: Update docs for slice since SliceExt was removed A lot has changed since this doc text was last touched up, and this is just a minor edit. I remove the trait section entirely since we don't use extension traits that much anymore, so there are no significant trait hilights for this module. --- src/libcollections/slice.rs | 74 +++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 41 deletions(-) diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 2a668b0869d25..688d730e25287 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -13,25 +13,23 @@ //! The `slice` module contains useful code to help work with slice values. //! Slices are a view into a block of memory represented as a pointer and a length. //! -//! ```rust -//! # #![feature(core)] +//! ``` //! // slicing a Vec -//! let vec = vec!(1, 2, 3); -//! let int_slice = vec.as_slice(); +//! let vec = vec![1, 2, 3]; +//! let int_slice = &vec[..]; //! // coercing an array to a slice //! let str_slice: &[&str] = &["one", "two", "three"]; //! ``` //! //! Slices are either mutable or shared. The shared slice type is `&[T]`, -//! while the mutable slice type is `&mut[T]`. For example, you can mutate the -//! block of memory that a mutable slice points to: +//! while the mutable slice type is `&mut [T]`, where `T` represents the element +//! type. For example, you can mutate the block of memory that a mutable slice +//! points to: //! -//! ```rust -//! let x: &mut[i32] = &mut [1, 2, 3]; +//! ``` +//! let x = &mut [1, 2, 3]; //! x[1] = 7; -//! assert_eq!(x[0], 1); -//! assert_eq!(x[1], 7); -//! assert_eq!(x[2], 3); +//! assert_eq!(x, &[1, 7, 3]); //! ``` //! //! Here are some of the things this module contains: @@ -41,49 +39,43 @@ //! There are several structs that are useful for slices, such as `Iter`, which //! represents iteration over a slice. //! -//! ## Traits -//! -//! A number of traits add methods that allow you to accomplish tasks -//! with slices, the most important being `SliceExt`. Other traits -//! apply only to slices of elements satisfying certain bounds (like -//! `Ord`). -//! -//! An example is the `slice` method which enables slicing syntax `[a..b]` that -//! returns an immutable "view" into a `Vec` or another slice from the index -//! interval `[a, b)`: -//! -//! ```rust -//! fn main() { -//! let numbers = [0, 1, 2]; -//! let last_numbers = &numbers[1..3]; -//! // last_numbers is now &[1, 2] -//! } -//! ``` -//! -//! ## Implementations of other traits +//! ## Trait Implementations //! //! There are several implementations of common traits for slices. Some examples //! include: //! //! * `Clone` -//! * `Eq`, `Ord` - for immutable slices whose element type are `Eq` or `Ord`. +//! * `Eq`, `Ord` - for slices whose element type are `Eq` or `Ord`. //! * `Hash` - for slices whose element type is `Hash` //! //! ## Iteration //! -//! The method `iter()` returns an iteration value for a slice. The iterator -//! yields references to the slice's elements, so if the element -//! type of the slice is `isize`, the element type of the iterator is `&isize`. +//! The slices implement `IntoIterator`. The iterators of yield references +//! to the slice elements. //! -//! ```rust -//! let numbers = [0, 1, 2]; -//! for &x in numbers.iter() { -//! println!("{} is a number!", x); +//! ``` +//! let numbers = &[0, 1, 2]; +//! for n in numbers { +//! println!("{} is a number!", n); //! } //! ``` //! -//! * `.iter_mut()` returns an iterator that allows modifying each value. -//! * Further iterators exist that split, chunk or permute the slice. +//! The mutable slice yields mutable references to the elements: +//! +//! ``` +//! let mut scores = [7, 8, 9]; +//! for score in &mut scores[..] { +//! *score += 1; +//! } +//! ``` +//! +//! This iterator yields mutable references to the slice's elements, so while the element +//! type of the slice is `i32`, the element type of the iterator is `&mut i32`. +//! +//! * `.iter()` and `.iter_mut()` are the explicit methods to return the default +//! iterators. +//! * Further methods that return iterators are `.split()`, `.splitn()`, +//! `.chunks()`, `.windows()` and more. #![doc(primitive = "slice")] #![stable(feature = "rust1", since = "1.0.0")]