diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-12-22 09:04:23 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-12-29 08:58:21 -0800 |
| commit | c32d03f4172580e3f33e4844ed3c01234dca2d53 (patch) | |
| tree | 70c57ebe6a3b5f6e8cb4609c918f9455671926be /src/libcore | |
| parent | 3dcc409fac18a258ba2a8af4345d9566ec8eebad (diff) | |
| download | rust-c32d03f4172580e3f33e4844ed3c01234dca2d53.tar.gz rust-c32d03f4172580e3f33e4844ed3c01234dca2d53.zip | |
std: Stabilize the prelude module
This commit is an implementation of [RFC 503][rfc] which is a stabilization story for the prelude. Most of the RFC was directly applied, removing reexports. Some reexports are kept around, however: * `range` remains until range syntax has landed to reduce churn. * `Path` and `GenericPath` remain until path reform lands. This is done to prevent many imports of `GenericPath` which will soon be removed. * All `io` traits remain until I/O reform lands so imports can be rewritten all at once to `std::io::prelude::*`. This is a breaking change because many prelude reexports have been removed, and the RFC can be consulted for the exact list of removed reexports, as well as to find the locations of where to import them. [rfc]: https://github.com/rust-lang/rfcs/blob/master/text/0503-prelude-stabilization.md [breaking-change] Closes #20068
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/cmp.rs | 5 | ||||
| -rw-r--r-- | src/libcore/ops.rs | 50 | ||||
| -rw-r--r-- | src/libcore/option.rs | 2 | ||||
| -rw-r--r-- | src/libcore/prelude.rs | 27 | ||||
| -rw-r--r-- | src/libcore/result.rs | 1 | ||||
| -rw-r--r-- | src/libcore/tuple.rs | 29 |
6 files changed, 59 insertions, 55 deletions
diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs index ca523db214b..4d72fb8ac92 100644 --- a/src/libcore/cmp.rs +++ b/src/libcore/cmp.rs @@ -112,11 +112,12 @@ impl Ordering { /// # Example /// /// ```rust + /// use std::cmp::Ordering::{Less, Equal, Greater}; + /// /// assert_eq!(Less.reverse(), Greater); /// assert_eq!(Equal.reverse(), Equal); /// assert_eq!(Greater.reverse(), Less); /// - /// /// let mut data: &mut [_] = &mut [2u, 10, 5, 8]; /// /// // sort the array from largest to smallest. @@ -157,6 +158,8 @@ pub trait Ord<Sized? Rhs = Self> for Sized?: Eq<Rhs> + PartialOrd<Rhs> { /// the expression `self <operator> other` if true. For example: /// /// ``` + /// use std::cmp::Ordering::{Less, Equal, Greater}; + /// /// assert_eq!( 5u.cmp(&10), Less); // because 5 < 10 /// assert_eq!(10u.cmp(&5), Greater); // because 10 > 5 /// assert_eq!( 5u.cmp(&5), Equal); // because 5 == 5 diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 0cd8c1d69d1..a2ef8d484a7 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -25,6 +25,8 @@ //! demonstrates adding and subtracting two `Point`s. //! //! ```rust +//! use std::ops::{Add, Sub}; +//! //! #[deriving(Show)] //! struct Point { //! x: int, @@ -68,13 +70,13 @@ use option::Option::{mod, Some, None}; /// struct HasDrop; /// /// impl Drop for HasDrop { -/// fn drop(&mut self) { -/// println!("Dropping!"); -/// } +/// fn drop(&mut self) { +/// println!("Dropping!"); +/// } /// } /// /// fn main() { -/// let _x = HasDrop; +/// let _x = HasDrop; /// } /// ``` #[lang="drop"] @@ -91,6 +93,8 @@ pub trait Drop { /// calling `add`, and therefore, `main` prints `Adding!`. /// /// ```rust +/// use std::ops::Add; +/// /// #[deriving(Copy)] /// struct Foo; /// @@ -130,6 +134,8 @@ add_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 } /// calling `sub`, and therefore, `main` prints `Subtracting!`. /// /// ```rust +/// use std::ops::Sub; +/// /// #[deriving(Copy)] /// struct Foo; /// @@ -169,6 +175,8 @@ sub_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 } /// calling `mul`, and therefore, `main` prints `Multiplying!`. /// /// ```rust +/// use std::ops::Mul; +/// /// #[deriving(Copy)] /// struct Foo; /// @@ -208,6 +216,8 @@ mul_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 } /// calling `div`, and therefore, `main` prints `Dividing!`. /// /// ``` +/// use std::ops::Div; +/// /// #[deriving(Copy)] /// struct Foo; /// @@ -247,6 +257,8 @@ div_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64 } /// calling `rem`, and therefore, `main` prints `Remainder-ing!`. /// /// ``` +/// use std::ops::Rem; +/// /// #[deriving(Copy)] /// struct Foo; /// @@ -300,6 +312,8 @@ rem_float_impl! { f64, fmod } /// `neg`, and therefore, `main` prints `Negating!`. /// /// ``` +/// use std::ops::Neg; +/// /// #[deriving(Copy)] /// struct Foo; /// @@ -352,6 +366,8 @@ macro_rules! neg_uint_impl { /// `neg`, and therefore, `main` prints `Negating!`. /// /// ``` +/// use std::ops::Neg; +/// /// struct Foo; /// /// impl Copy for Foo {} @@ -411,6 +427,8 @@ neg_uint_impl! { u64, i64 } /// `not`, and therefore, `main` prints `Not-ing!`. /// /// ``` +/// use std::ops::Not; +/// /// #[deriving(Copy)] /// struct Foo; /// @@ -453,6 +471,8 @@ macro_rules! not_impl { /// `not`, and therefore, `main` prints `Not-ing!`. /// /// ``` +/// use std::ops::Not; +/// /// struct Foo; /// /// impl Copy for Foo {} @@ -495,6 +515,8 @@ not_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 } /// calling `bitand`, and therefore, `main` prints `Bitwise And-ing!`. /// /// ``` +/// use std::ops::BitAnd; +/// /// #[deriving(Copy)] /// struct Foo; /// @@ -534,6 +556,8 @@ bitand_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 } /// calling `bitor`, and therefore, `main` prints `Bitwise Or-ing!`. /// /// ``` +/// use std::ops::BitOr; +/// /// #[deriving(Copy)] /// struct Foo; /// @@ -573,6 +597,8 @@ bitor_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 } /// calling `bitxor`, and therefore, `main` prints `Bitwise Xor-ing!`. /// /// ``` +/// use std::ops::BitXor; +/// /// #[deriving(Copy)] /// struct Foo; /// @@ -612,6 +638,8 @@ bitxor_impl! { bool uint u8 u16 u32 u64 int i8 i16 i32 i64 } /// calling `shl`, and therefore, `main` prints `Shifting left!`. /// /// ``` +/// use std::ops::Shl; +/// /// #[deriving(Copy)] /// struct Foo; /// @@ -653,6 +681,8 @@ shl_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 } /// calling `shr`, and therefore, `main` prints `Shifting right!`. /// /// ``` +/// use std::ops::Shr; +/// /// #[deriving(Copy)] /// struct Foo; /// @@ -693,6 +723,8 @@ shr_impl! { uint u8 u16 u32 u64 int i8 i16 i32 i64 } /// calling `index`, and therefore, `main` prints `Indexing!`. /// /// ``` +/// use std::ops::Index; +/// /// #[deriving(Copy)] /// struct Foo; /// @@ -722,6 +754,8 @@ pub trait Index<Sized? Index, Sized? Result> for Sized? { /// calling `index_mut`, and therefore, `main` prints `Indexing!`. /// /// ``` +/// use std::ops::IndexMut; +/// /// #[deriving(Copy)] /// struct Foo; /// @@ -751,6 +785,8 @@ pub trait IndexMut<Sized? Index, Sized? Result> for Sized? { /// calling `slice_to`, and therefore, `main` prints `Slicing!`. /// /// ```ignore +/// use std::ops::Slice; +/// /// #[deriving(Copy)] /// struct Foo; /// @@ -798,6 +834,8 @@ pub trait Slice<Sized? Idx, Sized? Result> for Sized? { /// calling `slice_from_mut`, and therefore, `main` prints `Slicing!`. /// /// ```ignore +/// use std::ops::SliceMut; +/// /// #[deriving(Copy)] /// struct Foo; /// @@ -918,6 +956,8 @@ impl<Idx: Clone + Step> Iterator<Idx> for RangeFrom<Idx> { /// struct. /// /// ``` +/// use std::ops::Deref; +/// /// struct DerefExample<T> { /// value: T /// } @@ -956,6 +996,8 @@ impl<'a, Sized? T> Deref<T> for &'a mut T { /// struct. /// /// ``` +/// use std::ops::{Deref, DerefMut}; +/// /// struct DerefMutExample<T> { /// value: T /// } diff --git a/src/libcore/option.rs b/src/libcore/option.rs index d831a57893b..ac0a6a78bae 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -723,6 +723,8 @@ impl<T: Default> Option<T> { /// `None` on error. /// /// ``` + /// use std::str::from_str; + /// /// let good_year_from_input = "1909"; /// let bad_year_from_input = "190blarg"; /// let good_year = good_year_from_input.parse().unwrap_or_default(); diff --git a/src/libcore/prelude.rs b/src/libcore/prelude.rs index f6abc8da79c..1fc377cda0a 100644 --- a/src/libcore/prelude.rs +++ b/src/libcore/prelude.rs @@ -30,39 +30,24 @@ // Reexported core operators pub use kinds::{Copy, Send, Sized, Sync}; -pub use ops::{Add, Sub, Mul, Div, Rem, Neg, Not}; -pub use ops::{BitAnd, BitOr, BitXor}; -pub use ops::{Drop, Deref, DerefMut}; -pub use ops::{Shl, Shr}; -pub use ops::{Index, IndexMut}; -pub use ops::{Slice, SliceMut}; -pub use ops::{Fn, FnMut, FnOnce}; +pub use ops::{Drop, Fn, FnMut, FnOnce}; // Reexported functions pub use iter::range; pub use mem::drop; -pub use str::from_str; // Reexported types and traits pub use char::Char; pub use clone::Clone; pub use cmp::{PartialEq, PartialOrd, Eq, Ord}; -pub use cmp::{Ordering, Equiv}; -pub use cmp::Ordering::{Less, Equal, Greater}; -pub use iter::{FromIterator, Extend, IteratorExt}; -pub use iter::{Iterator, DoubleEndedIterator, DoubleEndedIteratorExt, RandomAccessIterator}; +pub use iter::{Extend, IteratorExt}; +pub use iter::{Iterator, DoubleEndedIterator, DoubleEndedIteratorExt}; pub use iter::{IteratorCloneExt, CloneIteratorExt}; -pub use iter::{IteratorOrdExt, MutableDoubleEndedIterator, ExactSizeIterator}; -pub use num::{ToPrimitive, FromPrimitive}; -pub use option::Option; -pub use option::Option::{Some, None}; +pub use iter::{IteratorOrdExt, ExactSizeIterator}; +pub use option::Option::{mod, Some, None}; pub use ptr::RawPtr; -pub use result::Result; -pub use result::Result::{Ok, Err}; +pub use result::Result::{mod, Ok, Err}; pub use str::{Str, StrExt}; -pub use tuple::{Tuple1, Tuple2, Tuple3, Tuple4}; -pub use tuple::{Tuple5, Tuple6, Tuple7, Tuple8}; -pub use tuple::{Tuple9, Tuple10, Tuple11, Tuple12}; pub use slice::{PartialEqSliceExt, OrdSliceExt}; pub use slice::{AsSlice, SliceExt}; diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 8014b4dc89d..c738f61e20a 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -449,6 +449,7 @@ impl<T, E> Result<T, E> { /// /// ``` /// use std::io::IoResult; + /// use std::str::from_str; /// /// let mut buffer = &mut b"1\n2\n3\n4\n"; /// diff --git a/src/libcore/tuple.rs b/src/libcore/tuple.rs index a92914c99e3..270c5c59058 100644 --- a/src/libcore/tuple.rs +++ b/src/libcore/tuple.rs @@ -32,35 +32,6 @@ //! * `PartialOrd` //! * `Ord` //! * `Default` -//! -//! # Examples -//! -//! Using methods: -//! -//! ``` -//! #[allow(deprecated)] -//! # fn main() { -//! let pair = ("pi", 3.14f64); -//! assert_eq!(pair.val0(), "pi"); -//! assert_eq!(pair.val1(), 3.14f64); -//! # } -//! ``` -//! -//! Using traits implemented for tuples: -//! -//! ``` -//! use std::default::Default; -//! -//! let a = (1i, 2i); -//! let b = (3i, 4i); -//! assert!(a != b); -//! -//! let c = b.clone(); -//! assert!(b == c); -//! -//! let d : (u32, f32) = Default::default(); -//! assert_eq!(d, (0u32, 0.0f32)); -//! ``` #![stable] |
