diff options
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/clone.rs | 22 | ||||
| -rw-r--r-- | src/libcore/finally.rs | 102 | ||||
| -rw-r--r-- | src/libcore/fmt/float.rs | 60 | ||||
| -rw-r--r-- | src/libcore/fmt/mod.rs | 6 | ||||
| -rw-r--r-- | src/libcore/intrinsics.rs | 62 | ||||
| -rw-r--r-- | src/libcore/iter.rs | 94 | ||||
| -rw-r--r-- | src/libcore/kinds.rs | 19 | ||||
| -rw-r--r-- | src/libcore/ops.rs | 1025 | ||||
| -rw-r--r-- | src/libcore/slice.rs | 56 |
9 files changed, 678 insertions, 768 deletions
diff --git a/src/libcore/clone.rs b/src/libcore/clone.rs index d13daf0964a..9f928f57e9e 100644 --- a/src/libcore/clone.rs +++ b/src/libcore/clone.rs @@ -8,18 +8,16 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -/*! The `Clone` trait for types that cannot be 'implicitly copied' - -In Rust, some simple types are "implicitly copyable" and when you -assign them or pass them as arguments, the receiver will get a copy, -leaving the original value in place. These types do not require -allocation to copy and do not have finalizers (i.e. they do not -contain owned boxes or implement `Drop`), so the compiler considers -them cheap and safe to copy. For other types copies must be made -explicitly, by convention implementing the `Clone` trait and calling -the `clone` method. - -*/ +//! The `Clone` trait for types that cannot be 'implicitly copied' +//! +//! In Rust, some simple types are "implicitly copyable" and when you +//! assign them or pass them as arguments, the receiver will get a copy, +//! leaving the original value in place. These types do not require +//! allocation to copy and do not have finalizers (i.e. they do not +//! contain owned boxes or implement `Drop`), so the compiler considers +//! them cheap and safe to copy. For other types copies must be made +//! explicitly, by convention implementing the `Clone` trait and calling +//! the `clone` method. #![unstable] diff --git a/src/libcore/finally.rs b/src/libcore/finally.rs index 2e358e7a74b..d2b7591b3ef 100644 --- a/src/libcore/finally.rs +++ b/src/libcore/finally.rs @@ -8,27 +8,25 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -/*! -The Finally trait provides a method, `finally` on -stack closures that emulates Java-style try/finally blocks. - -Using the `finally` method is sometimes convenient, but the type rules -prohibit any shared, mutable state between the "try" case and the -"finally" case. For advanced cases, the `try_finally` function can -also be used. See that function for more details. - -# Example - -``` -use std::finally::Finally; - -(|| { - // ... -}).finally(|| { - // this code is always run -}) -``` -*/ +//! The Finally trait provides a method, `finally` on +//! stack closures that emulates Java-style try/finally blocks. +//! +//! Using the `finally` method is sometimes convenient, but the type rules +//! prohibit any shared, mutable state between the "try" case and the +//! "finally" case. For advanced cases, the `try_finally` function can +//! also be used. See that function for more details. +//! +//! # Example +//! +//! ``` +//! use std::finally::Finally; +//! +//! (|| { +//! // ... +//! }).finally(|| { +//! // this code is always run +//! }) +//! ``` #![experimental] @@ -58,38 +56,36 @@ impl<T> Finally<T> for fn() -> T { } } -/** - * The most general form of the `finally` functions. The function - * `try_fn` will be invoked first; whether or not it panics, the - * function `finally_fn` will be invoked next. The two parameters - * `mutate` and `drop` are used to thread state through the two - * closures. `mutate` is used for any shared, mutable state that both - * closures require access to; `drop` is used for any state that the - * `try_fn` requires ownership of. - * - * **WARNING:** While shared, mutable state between the try and finally - * function is often necessary, one must be very careful; the `try` - * function could have panicked at any point, so the values of the shared - * state may be inconsistent. - * - * # Example - * - * ``` - * use std::finally::try_finally; - * - * struct State<'a> { buffer: &'a mut [u8], len: uint } - * # let mut buf = []; - * let mut state = State { buffer: &mut buf, len: 0 }; - * try_finally( - * &mut state, (), - * |state, ()| { - * // use state.buffer, state.len - * }, - * |state| { - * // use state.buffer, state.len to cleanup - * }) - * ``` - */ +/// The most general form of the `finally` functions. The function +/// `try_fn` will be invoked first; whether or not it panics, the +/// function `finally_fn` will be invoked next. The two parameters +/// `mutate` and `drop` are used to thread state through the two +/// closures. `mutate` is used for any shared, mutable state that both +/// closures require access to; `drop` is used for any state that the +/// `try_fn` requires ownership of. +/// +/// **WARNING:** While shared, mutable state between the try and finally +/// function is often necessary, one must be very careful; the `try` +/// function could have panicked at any point, so the values of the shared +/// state may be inconsistent. +/// +/// # Example +/// +/// ``` +/// use std::finally::try_finally; +/// +/// struct State<'a> { buffer: &'a mut [u8], len: uint } +/// # let mut buf = []; +/// let mut state = State { buffer: &mut buf, len: 0 }; +/// try_finally( +/// &mut state, (), +/// |state, ()| { +/// // use state.buffer, state.len +/// }, +/// |state| { +/// // use state.buffer, state.len to cleanup +/// }) +/// ``` pub fn try_finally<T,U,R>(mutate: &mut T, drop: U, try_fn: |&mut T, U| -> R, diff --git a/src/libcore/fmt/float.rs b/src/libcore/fmt/float.rs index 31a46c26e2a..1e31df83779 100644 --- a/src/libcore/fmt/float.rs +++ b/src/libcore/fmt/float.rs @@ -54,36 +54,36 @@ pub enum SignFormat { static DIGIT_E_RADIX: uint = ('e' as uint) - ('a' as uint) + 11u; -/** - * Converts a number to its string representation as a byte vector. - * This is meant to be a common base implementation for all numeric string - * conversion functions like `to_string()` or `to_str_radix()`. - * - * # Arguments - * - `num` - The number to convert. Accepts any number that - * implements the numeric traits. - * - `radix` - Base to use. Accepts only the values 2-36. If the exponential notation - * is used, then this base is only used for the significand. The exponent - * itself always printed using a base of 10. - * - `negative_zero` - Whether to treat the special value `-0` as - * `-0` or as `+0`. - * - `sign` - How to emit the sign. See `SignFormat`. - * - `digits` - The amount of digits to use for emitting the fractional - * part, if any. See `SignificantDigits`. - * - `exp_format` - Whether or not to use the exponential (scientific) notation. - * See `ExponentFormat`. - * - `exp_capital` - Whether or not to use a capital letter for the exponent sign, if - * exponential notation is desired. - * - `f` - A closure to invoke with the bytes representing the - * float. - * - * # Panics - * - Panics if `radix` < 2 or `radix` > 36. - * - Panics if `radix` > 14 and `exp_format` is `ExpDec` due to conflict - * between digit and exponent sign `'e'`. - * - Panics if `radix` > 25 and `exp_format` is `ExpBin` due to conflict - * between digit and exponent sign `'p'`. - */ +/// Converts a number to its string representation as a byte vector. +/// This is meant to be a common base implementation for all numeric string +/// conversion functions like `to_string()` or `to_str_radix()`. +/// +/// # Arguments +/// +/// - `num` - The number to convert. Accepts any number that +/// implements the numeric traits. +/// - `radix` - Base to use. Accepts only the values 2-36. If the exponential notation +/// is used, then this base is only used for the significand. The exponent +/// itself always printed using a base of 10. +/// - `negative_zero` - Whether to treat the special value `-0` as +/// `-0` or as `+0`. +/// - `sign` - How to emit the sign. See `SignFormat`. +/// - `digits` - The amount of digits to use for emitting the fractional +/// part, if any. See `SignificantDigits`. +/// - `exp_format` - Whether or not to use the exponential (scientific) notation. +/// See `ExponentFormat`. +/// - `exp_capital` - Whether or not to use a capital letter for the exponent sign, if +/// exponential notation is desired. +/// - `f` - A closure to invoke with the bytes representing the +/// float. +/// +/// # Panics +/// +/// - Panics if `radix` < 2 or `radix` > 36. +/// - Panics if `radix` > 14 and `exp_format` is `ExpDec` due to conflict +/// between digit and exponent sign `'e'`. +/// - Panics if `radix` > 25 and `exp_format` is `ExpBin` due to conflict +/// between digit and exponent sign `'p'`. pub fn float_to_str_bytes_common<T: Float, U>( num: T, radix: uint, diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index 605148beb90..1d6906c13a8 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -85,7 +85,7 @@ pub struct Formatter<'a> { width: Option<uint>, precision: Option<uint>, - buf: &'a mut FormatWriter+'a, + buf: &'a mut (FormatWriter+'a), curarg: slice::Items<'a, Argument<'a>>, args: &'a [Argument<'a>], } @@ -565,7 +565,7 @@ impl<'a, Sized? T: Show> Show for &'a T { impl<'a, Sized? T: Show> Show for &'a mut T { fn fmt(&self, f: &mut Formatter) -> Result { (**self).fmt(f) } } -impl<'a> Show for &'a Show+'a { +impl<'a> Show for &'a (Show+'a) { fn fmt(&self, f: &mut Formatter) -> Result { (*self).fmt(f) } } @@ -724,7 +724,7 @@ macro_rules! tuple ( tuple! { T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, } -impl<'a> Show for &'a any::Any+'a { +impl<'a> Show for &'a (any::Any+'a) { fn fmt(&self, f: &mut Formatter) -> Result { f.pad("&Any") } } diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs index 067ef47a86b..78c74075d48 100644 --- a/src/libcore/intrinsics.rs +++ b/src/libcore/intrinsics.rs @@ -8,38 +8,36 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -/*! rustc compiler intrinsics. - -The corresponding definitions are in librustc/middle/trans/foreign.rs. - -# Volatiles - -The volatile intrinsics provide operations intended to act on I/O -memory, which are guaranteed to not be reordered by the compiler -across other volatile intrinsics. See the LLVM documentation on -[[volatile]]. - -[volatile]: http://llvm.org/docs/LangRef.html#volatile-memory-accesses - -# Atomics - -The atomic intrinsics provide common atomic operations on machine -words, with multiple possible memory orderings. They obey the same -semantics as C++11. See the LLVM documentation on [[atomics]]. - -[atomics]: http://llvm.org/docs/Atomics.html - -A quick refresher on memory ordering: - -* Acquire - a barrier for acquiring a lock. Subsequent reads and writes - take place after the barrier. -* Release - a barrier for releasing a lock. Preceding reads and writes - take place before the barrier. -* Sequentially consistent - sequentially consistent operations are - guaranteed to happen in order. This is the standard mode for working - with atomic types and is equivalent to Java's `volatile`. - -*/ +//! rustc compiler intrinsics. +//! +//! The corresponding definitions are in librustc/middle/trans/foreign.rs. +//! +//! # Volatiles +//! +//! The volatile intrinsics provide operations intended to act on I/O +//! memory, which are guaranteed to not be reordered by the compiler +//! across other volatile intrinsics. See the LLVM documentation on +//! [[volatile]]. +//! +//! [volatile]: http://llvm.org/docs/LangRef.html#volatile-memory-accesses +//! +//! # Atomics +//! +//! The atomic intrinsics provide common atomic operations on machine +//! words, with multiple possible memory orderings. They obey the same +//! semantics as C++11. See the LLVM documentation on [[atomics]]. +//! +//! [atomics]: http://llvm.org/docs/Atomics.html +//! +//! A quick refresher on memory ordering: +//! +//! * Acquire - a barrier for acquiring a lock. Subsequent reads and writes +//! take place after the barrier. +//! * Release - a barrier for releasing a lock. Preceding reads and writes +//! take place before the barrier. +//! * Sequentially consistent - sequentially consistent operations are +//! guaranteed to happen in order. This is the standard mode for working +//! with atomic types and is equivalent to Java's `volatile`. #![experimental] #![allow(missing_docs)] diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 496e7979b72..2d488a4b155 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -8,55 +8,51 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -/*! - -Composable external iterators - -# The `Iterator` trait - -This module defines Rust's core iteration trait. The `Iterator` trait has one -unimplemented method, `next`. All other methods are derived through default -methods to perform operations such as `zip`, `chain`, `enumerate`, and `fold`. - -The goal of this module is to unify iteration across all containers in Rust. -An iterator can be considered as a state machine which is used to track which -element will be yielded next. - -There are various extensions also defined in this module to assist with various -types of iteration, such as the `DoubleEndedIterator` for iterating in reverse, -the `FromIterator` trait for creating a container from an iterator, and much -more. - -## Rust's `for` loop - -The special syntax used by rust's `for` loop is based around the `Iterator` -trait defined in this module. For loops can be viewed as a syntactical expansion -into a `loop`, for example, the `for` loop in this example is essentially -translated to the `loop` below. - -```rust -let values = vec![1i, 2, 3]; - -// "Syntactical sugar" taking advantage of an iterator -for &x in values.iter() { - println!("{}", x); -} - -// Rough translation of the iteration without a `for` iterator. -let mut it = values.iter(); -loop { - match it.next() { - Some(&x) => { - println!("{}", x); - } - None => { break } - } -} -``` - -This `for` loop syntax can be applied to any iterator over any type. - -*/ +//! Composable external iterators +//! +//! # The `Iterator` trait +//! +//! This module defines Rust's core iteration trait. The `Iterator` trait has one +//! unimplemented method, `next`. All other methods are derived through default +//! methods to perform operations such as `zip`, `chain`, `enumerate`, and `fold`. +//! +//! The goal of this module is to unify iteration across all containers in Rust. +//! An iterator can be considered as a state machine which is used to track which +//! element will be yielded next. +//! +//! There are various extensions also defined in this module to assist with various +//! types of iteration, such as the `DoubleEndedIterator` for iterating in reverse, +//! the `FromIterator` trait for creating a container from an iterator, and much +//! more. +//! +//! ## Rust's `for` loop +//! +//! The special syntax used by rust's `for` loop is based around the `Iterator` +//! trait defined in this module. For loops can be viewed as a syntactical expansion +//! into a `loop`, for example, the `for` loop in this example is essentially +//! translated to the `loop` below. +//! +//! ```rust +//! let values = vec![1i, 2, 3]; +//! +//! // "Syntactical sugar" taking advantage of an iterator +//! for &x in values.iter() { +//! println!("{}", x); +//! } +//! +//! // Rough translation of the iteration without a `for` iterator. +//! let mut it = values.iter(); +//! loop { +//! match it.next() { +//! Some(&x) => { +//! println!("{}", x); +//! } +//! None => { break } +//! } +//! } +//! ``` +//! +//! This `for` loop syntax can be applied to any iterator over any type. pub use self::MinMaxResult::*; diff --git a/src/libcore/kinds.rs b/src/libcore/kinds.rs index 6489101f7b9..0c2cb9d5910 100644 --- a/src/libcore/kinds.rs +++ b/src/libcore/kinds.rs @@ -8,17 +8,14 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -/*! -Primitive traits representing basic 'kinds' of types - -Rust types can be classified in various useful ways according to -intrinsic properties of the type. These classifications, often called -'kinds', are represented as traits. - -They cannot be implemented by user code, but are instead implemented -by the compiler automatically for the types to which they apply. - -*/ +//! Primitive traits representing basic 'kinds' of types +//! +//! Rust types can be classified in various useful ways according to +//! intrinsic properties of the type. These classifications, often called +//! 'kinds', are represented as traits. +//! +//! They cannot be implemented by user code, but are instead implemented +//! by the compiler automatically for the types to which they apply. /// Types able to be transferred across task boundaries. #[lang="send"] diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 185c937eb6b..d85481098e4 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -8,109 +8,99 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -/*! - * - * Overloadable operators - * - * Implementing these traits allows you to get an effect similar to - * overloading operators. - * - * The values for the right hand side of an operator are automatically - * borrowed, so `a + b` is sugar for `a.add(&b)`. - * - * All of these traits are imported by the prelude, so they are available in - * every Rust program. - * - * # Example - * - * This example creates a `Point` struct that implements `Add` and `Sub`, and then - * demonstrates adding and subtracting two `Point`s. - * - * ```rust - * #[deriving(Show)] - * struct Point { - * x: int, - * y: int - * } - * - * impl Add<Point, Point> for Point { - * fn add(&self, other: &Point) -> Point { - * Point {x: self.x + other.x, y: self.y + other.y} - * } - * } - * - * impl Sub<Point, Point> for Point { - * fn sub(&self, other: &Point) -> Point { - * Point {x: self.x - other.x, y: self.y - other.y} - * } - * } - * fn main() { - * println!("{}", Point {x: 1, y: 0} + Point {x: 2, y: 3}); - * println!("{}", Point {x: 1, y: 0} - Point {x: 2, y: 3}); - * } - * ``` - * - * See the documentation for each trait for a minimum implementation that prints - * something to the screen. - * - */ +//! Overloadable operators +//! +//! Implementing these traits allows you to get an effect similar to +//! overloading operators. +//! +//! The values for the right hand side of an operator are automatically +//! borrowed, so `a + b` is sugar for `a.add(&b)`. +//! +//! All of these traits are imported by the prelude, so they are available in +//! every Rust program. +//! +//! # Example +//! +//! This example creates a `Point` struct that implements `Add` and `Sub`, and then +//! demonstrates adding and subtracting two `Point`s. +//! +//! ```rust +//! #[deriving(Show)] +//! struct Point { +//! x: int, +//! y: int +//! } +//! +//! impl Add<Point, Point> for Point { +//! fn add(&self, other: &Point) -> Point { +//! Point {x: self.x + other.x, y: self.y + other.y} +//! } +//! } +//! +//! impl Sub<Point, Point> for Point { +//! fn sub(&self, other: &Point) -> Point { +//! Point {x: self.x - other.x, y: self.y - other.y} +//! } +//! } +//! fn main() { +//! println!("{}", Point {x: 1, y: 0} + Point {x: 2, y: 3}); +//! println!("{}", Point {x: 1, y: 0} - Point {x: 2, y: 3}); +//! } +//! ``` +//! +//! See the documentation for each trait for a minimum implementation that prints +//! something to the screen. use kinds::Sized; -/** - * - * The `Drop` trait is used to run some code when a value goes out of scope. This - * is sometimes called a 'destructor'. - * - * # Example - * - * A trivial implementation of `Drop`. The `drop` method is called when `_x` goes - * out of scope, and therefore `main` prints `Dropping!`. - * - * ```rust - * struct HasDrop; - * - * impl Drop for HasDrop { - * fn drop(&mut self) { - * println!("Dropping!"); - * } - * } - * - * fn main() { - * let _x = HasDrop; - * } - * ``` - */ +/// The `Drop` trait is used to run some code when a value goes out of scope. This +/// is sometimes called a 'destructor'. +/// +/// # Example +/// +/// A trivial implementation of `Drop`. The `drop` method is called when `_x` goes +/// out of scope, and therefore `main` prints `Dropping!`. +/// +/// ```rust +/// struct HasDrop; +/// +/// impl Drop for HasDrop { +/// fn drop(&mut self) { +/// println!("Dropping!"); +/// } +/// } +/// +/// fn main() { +/// let _x = HasDrop; +/// } +/// ``` #[lang="drop"] pub trait Drop { /// The `drop` method, called when the value goes out of scope. fn drop(&mut self); } -/** - * - * The `Add` trait is used to specify the functionality of `+`. - * - * # Example - * - * A trivial implementation of `Add`. When `Foo + Foo` happens, it ends up - * calling `add`, and therefore, `main` prints `Adding!`. - * - * ```rust - * struct Foo; - * - * impl Add<Foo, Foo> for Foo { - * fn add(&self, _rhs: &Foo) -> Foo { - * println!("Adding!"); - * *self - * } - * } - * - * fn main() { - * Foo + Foo; - * } - * ``` - */ +/// The `Add` trait is used to specify the functionality of `+`. +/// +/// # Example +/// +/// A trivial implementation of `Add`. When `Foo + Foo` happens, it ends up +/// calling `add`, and therefore, `main` prints `Adding!`. +/// +/// ```rust +/// struct Foo; +/// +/// impl Add<Foo, Foo> for Foo { +/// fn add(&self, _rhs: &Foo) -> Foo { +/// println!("Adding!"); +/// *self +/// } +/// } +/// +/// fn main() { +/// Foo + Foo; +/// } +/// ``` #[lang="add"] pub trait Add<Sized? RHS,Result> for Sized? { /// The method for the `+` operator @@ -128,30 +118,27 @@ macro_rules! add_impl( add_impl!(uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64) -/** - * - * The `Sub` trait is used to specify the functionality of `-`. - * - * # Example - * - * A trivial implementation of `Sub`. When `Foo - Foo` happens, it ends up - * calling `sub`, and therefore, `main` prints `Subtracting!`. - * - * ```rust - * struct Foo; - * - * impl Sub<Foo, Foo> for Foo { - * fn sub(&self, _rhs: &Foo) -> Foo { - * println!("Subtracting!"); - * *self - * } - * } - * - * fn main() { - * Foo - Foo; - * } - * ``` - */ +/// The `Sub` trait is used to specify the functionality of `-`. +/// +/// # Example +/// +/// A trivial implementation of `Sub`. When `Foo - Foo` happens, it ends up +/// calling `sub`, and therefore, `main` prints `Subtracting!`. +/// +/// ```rust +/// struct Foo; +/// +/// impl Sub<Foo, Foo> for Foo { +/// fn sub(&self, _rhs: &Foo) -> Foo { +/// println!("Subtracting!"); +/// *self +/// } +/// } +/// +/// fn main() { +/// Foo - Foo; +/// } +/// ``` #[lang="sub"] pub trait Sub<Sized? RHS, Result> for Sized? { /// The method for the `-` operator @@ -169,30 +156,27 @@ macro_rules! sub_impl( sub_impl!(uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64) -/** - * - * The `Mul` trait is used to specify the functionality of `*`. - * - * # Example - * - * A trivial implementation of `Mul`. When `Foo * Foo` happens, it ends up - * calling `mul`, and therefore, `main` prints `Multiplying!`. - * - * ```rust - * struct Foo; - * - * impl Mul<Foo, Foo> for Foo { - * fn mul(&self, _rhs: &Foo) -> Foo { - * println!("Multiplying!"); - * *self - * } - * } - * - * fn main() { - * Foo * Foo; - * } - * ``` - */ +/// The `Mul` trait is used to specify the functionality of `*`. +/// +/// # Example +/// +/// A trivial implementation of `Mul`. When `Foo * Foo` happens, it ends up +/// calling `mul`, and therefore, `main` prints `Multiplying!`. +/// +/// ```rust +/// struct Foo; +/// +/// impl Mul<Foo, Foo> for Foo { +/// fn mul(&self, _rhs: &Foo) -> Foo { +/// println!("Multiplying!"); +/// *self +/// } +/// } +/// +/// fn main() { +/// Foo * Foo; +/// } +/// ``` #[lang="mul"] pub trait Mul<Sized? RHS, Result> for Sized? { /// The method for the `*` operator @@ -210,30 +194,27 @@ macro_rules! mul_impl( mul_impl!(uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64) -/** - * - * The `Div` trait is used to specify the functionality of `/`. - * - * # Example - * - * A trivial implementation of `Div`. When `Foo / Foo` happens, it ends up - * calling `div`, and therefore, `main` prints `Dividing!`. - * - * ``` - * struct Foo; - * - * impl Div<Foo, Foo> for Foo { - * fn div(&self, _rhs: &Foo) -> Foo { - * println!("Dividing!"); - * *self - * } - * } - * - * fn main() { - * Foo / Foo; - * } - * ``` - */ +/// The `Div` trait is used to specify the functionality of `/`. +/// +/// # Example +/// +/// A trivial implementation of `Div`. When `Foo / Foo` happens, it ends up +/// calling `div`, and therefore, `main` prints `Dividing!`. +/// +/// ``` +/// struct Foo; +/// +/// impl Div<Foo, Foo> for Foo { +/// fn div(&self, _rhs: &Foo) -> Foo { +/// println!("Dividing!"); +/// *self +/// } +/// } +/// +/// fn main() { +/// Foo / Foo; +/// } +/// ``` #[lang="div"] pub trait Div<Sized? RHS, Result> for Sized? { /// The method for the `/` operator @@ -251,30 +232,27 @@ macro_rules! div_impl( div_impl!(uint u8 u16 u32 u64 int i8 i16 i32 i64 f32 f64) -/** - * - * The `Rem` trait is used to specify the functionality of `%`. - * - * # Example - * - * A trivial implementation of `Rem`. When `Foo % Foo` happens, it ends up - * calling `rem`, and therefore, `main` prints `Remainder-ing!`. - * - * ``` - * struct Foo; - * - * impl Rem<Foo, Foo> for Foo { - * fn rem(&self, _rhs: &Foo) -> Foo { - * println!("Remainder-ing!"); - * *self - * } - * } - * - * fn main() { - * Foo % Foo; - * } - * ``` - */ +/// The `Rem` trait is used to specify the functionality of `%`. +/// +/// # Example +/// +/// A trivial implementation of `Rem`. When `Foo % Foo` happens, it ends up +/// calling `rem`, and therefore, `main` prints `Remainder-ing!`. +/// +/// ``` +/// struct Foo; +/// +/// impl Rem<Foo, Foo> for Foo { +/// fn rem(&self, _rhs: &Foo) -> Foo { +/// println!("Remainder-ing!"); +/// *self +/// } +/// } +/// +/// fn main() { +/// Foo % Foo; +/// } +/// ``` #[lang="rem"] pub trait Rem<Sized? RHS, Result> for Sized? { /// The method for the `%` operator @@ -306,30 +284,27 @@ rem_impl!(uint u8 u16 u32 u64 int i8 i16 i32 i64) rem_float_impl!(f32, fmodf) rem_float_impl!(f64, fmod) -/** - * - * The `Neg` trait is used to specify the functionality of unary `-`. - * - * # Example - * - * A trivial implementation of `Neg`. When `-Foo` happens, it ends up calling - * `neg`, and therefore, `main` prints `Negating!`. - * - * ``` - * struct Foo; - * - * impl Neg<Foo> for Foo { - * fn neg(&self) -> Foo { - * println!("Negating!"); - * *self - * } - * } - * - * fn main() { - * -Foo; - * } - * ``` - */ +/// The `Neg` trait is used to specify the functionality of unary `-`. +/// +/// # Example +/// +/// A trivial implementation of `Neg`. When `-Foo` happens, it ends up calling +/// `neg`, and therefore, `main` prints `Negating!`. +/// +/// ``` +/// struct Foo; +/// +/// impl Neg<Foo> for Foo { +/// fn neg(&self) -> Foo { +/// println!("Negating!"); +/// *self +/// } +/// } +/// +/// fn main() { +/// -Foo; +/// } +/// ``` #[lang="neg"] pub trait Neg<Result> for Sized? { /// The method for the unary `-` operator @@ -363,30 +338,27 @@ neg_uint_impl!(u32, i32) neg_uint_impl!(u64, i64) -/** - * - * The `Not` trait is used to specify the functionality of unary `!`. - * - * # Example - * - * A trivial implementation of `Not`. When `!Foo` happens, it ends up calling - * `not`, and therefore, `main` prints `Not-ing!`. - * - * ``` - * struct Foo; - * - * impl Not<Foo> for Foo { - * fn not(&self) -> Foo { - * println!("Not-ing!"); - * *self - * } - * } - * - * fn main() { - * !Foo; - * } - * ``` - */ +/// The `Not` trait is used to specify the functionality of unary `!`. +/// +/// # Example +/// +/// A trivial implementation of `Not`. When `!Foo` happens, it ends up calling +/// `not`, and therefore, `main` prints `Not-ing!`. +/// +/// ``` +/// struct Foo; +/// +/// impl Not<Foo> for Foo { +/// fn not(&self) -> Foo { +/// println!("Not-ing!"); +/// *self +/// } +/// } +/// +/// fn main() { +/// !Foo; +/// } +/// ``` #[lang="not"] pub trait Not<Result> for Sized? { /// The method for the unary `!` operator @@ -405,30 +377,27 @@ macro_rules! not_impl( not_impl!(bool uint u8 u16 u32 u64 int i8 i16 i32 i64) -/** - * - * The `BitAnd` trait is used to specify the functionality of `&`. - * - * # Example - * - * A trivial implementation of `BitAnd`. When `Foo & Foo` happens, it ends up - * calling `bitand`, and therefore, `main` prints `Bitwise And-ing!`. - * - * ``` - * struct Foo; - * - * impl BitAnd<Foo, Foo> for Foo { - * fn bitand(&self, _rhs: &Foo) -> Foo { - * println!("Bitwise And-ing!"); - * *self - * } - * } - * - * fn main() { - * Foo & Foo; - * } - * ``` - */ +/// The `BitAnd` trait is used to specify the functionality of `&`. +/// +/// # Example +/// +/// A trivial implementation of `BitAnd`. When `Foo & Foo` happens, it ends up +/// calling `bitand`, and therefore, `main` prints `Bitwise And-ing!`. +/// +/// ``` +/// struct Foo; +/// +/// impl BitAnd<Foo, Foo> for Foo { +/// fn bitand(&self, _rhs: &Foo) -> Foo { +/// println!("Bitwise And-ing!"); +/// *self +/// } +/// } +/// +/// fn main() { +/// Foo & Foo; +/// } +/// ``` #[lang="bitand"] pub trait BitAnd<Sized? RHS, Result> for Sized? { /// The method for the `&` operator @@ -446,30 +415,27 @@ macro_rules! bitand_impl( bitand_impl!(bool uint u8 u16 u32 u64 int i8 i16 i32 i64) -/** - * - * The `BitOr` trait is used to specify the functionality of `|`. - * - * # Example - * - * A trivial implementation of `BitOr`. When `Foo | Foo` happens, it ends up - * calling `bitor`, and therefore, `main` prints `Bitwise Or-ing!`. - * - * ``` - * struct Foo; - * - * impl BitOr<Foo, Foo> for Foo { - * fn bitor(&self, _rhs: &Foo) -> Foo { - * println!("Bitwise Or-ing!"); - * *self - * } - * } - * - * fn main() { - * Foo | Foo; - * } - * ``` - */ +/// The `BitOr` trait is used to specify the functionality of `|`. +/// +/// # Example +/// +/// A trivial implementation of `BitOr`. When `Foo | Foo` happens, it ends up +/// calling `bitor`, and therefore, `main` prints `Bitwise Or-ing!`. +/// +/// ``` +/// struct Foo; +/// +/// impl BitOr<Foo, Foo> for Foo { +/// fn bitor(&self, _rhs: &Foo) -> Foo { +/// println!("Bitwise Or-ing!"); +/// *self +/// } +/// } +/// +/// fn main() { +/// Foo | Foo; +/// } +/// ``` #[lang="bitor"] pub trait BitOr<Sized? RHS, Result> for Sized? { /// The method for the `|` operator @@ -487,30 +453,27 @@ macro_rules! bitor_impl( bitor_impl!(bool uint u8 u16 u32 u64 int i8 i16 i32 i64) -/** - * - * The `BitXor` trait is used to specify the functionality of `^`. - * - * # Example - * - * A trivial implementation of `BitXor`. When `Foo ^ Foo` happens, it ends up - * calling `bitxor`, and therefore, `main` prints `Bitwise Xor-ing!`. - * - * ``` - * struct Foo; - * - * impl BitXor<Foo, Foo> for Foo { - * fn bitxor(&self, _rhs: &Foo) -> Foo { - * println!("Bitwise Xor-ing!"); - * *self - * } - * } - * - * fn main() { - * Foo ^ Foo; - * } - * ``` - */ +/// The `BitXor` trait is used to specify the functionality of `^`. +/// +/// # Example +/// +/// A trivial implementation of `BitXor`. When `Foo ^ Foo` happens, it ends up +/// calling `bitxor`, and therefore, `main` prints `Bitwise Xor-ing!`. +/// +/// ``` +/// struct Foo; +/// +/// impl BitXor<Foo, Foo> for Foo { +/// fn bitxor(&self, _rhs: &Foo) -> Foo { +/// println!("Bitwise Xor-ing!"); +/// *self +/// } +/// } +/// +/// fn main() { +/// Foo ^ Foo; +/// } +/// ``` #[lang="bitxor"] pub trait BitXor<Sized? RHS, Result> for Sized? { /// The method for the `^` operator @@ -528,30 +491,27 @@ macro_rules! bitxor_impl( bitxor_impl!(bool uint u8 u16 u32 u64 int i8 i16 i32 i64) -/** - * - * The `Shl` trait is used to specify the functionality of `<<`. - * - * # Example - * - * A trivial implementation of `Shl`. When `Foo << Foo` happens, it ends up - * calling `shl`, and therefore, `main` prints `Shifting left!`. - * - * ``` - * struct Foo; - * - * impl Shl<Foo, Foo> for Foo { - * fn shl(&self, _rhs: &Foo) -> Foo { - * println!("Shifting left!"); - * *self - * } - * } - * - * fn main() { - * Foo << Foo; - * } - * ``` - */ +/// The `Shl` trait is used to specify the functionality of `<<`. +/// +/// # Example +/// +/// A trivial implementation of `Shl`. When `Foo << Foo` happens, it ends up +/// calling `shl`, and therefore, `main` prints `Shifting left!`. +/// +/// ``` +/// struct Foo; +/// +/// impl Shl<Foo, Foo> for Foo { +/// fn shl(&self, _rhs: &Foo) -> Foo { +/// println!("Shifting left!"); +/// *self +/// } +/// } +/// +/// fn main() { +/// Foo << Foo; +/// } +/// ``` #[lang="shl"] pub trait Shl<Sized? RHS, Result> for Sized? { /// The method for the `<<` operator @@ -571,30 +531,27 @@ macro_rules! shl_impl( shl_impl!(uint u8 u16 u32 u64 int i8 i16 i32 i64) -/** - * - * The `Shr` trait is used to specify the functionality of `>>`. - * - * # Example - * - * A trivial implementation of `Shr`. When `Foo >> Foo` happens, it ends up - * calling `shr`, and therefore, `main` prints `Shifting right!`. - * - * ``` - * struct Foo; - * - * impl Shr<Foo, Foo> for Foo { - * fn shr(&self, _rhs: &Foo) -> Foo { - * println!("Shifting right!"); - * *self - * } - * } - * - * fn main() { - * Foo >> Foo; - * } - * ``` - */ +/// The `Shr` trait is used to specify the functionality of `>>`. +/// +/// # Example +/// +/// A trivial implementation of `Shr`. When `Foo >> Foo` happens, it ends up +/// calling `shr`, and therefore, `main` prints `Shifting right!`. +/// +/// ``` +/// struct Foo; +/// +/// impl Shr<Foo, Foo> for Foo { +/// fn shr(&self, _rhs: &Foo) -> Foo { +/// println!("Shifting right!"); +/// *self +/// } +/// } +/// +/// fn main() { +/// Foo >> Foo; +/// } +/// ``` #[lang="shr"] pub trait Shr<Sized? RHS, Result> for Sized? { /// The method for the `>>` operator @@ -612,105 +569,96 @@ macro_rules! shr_impl( shr_impl!(uint u8 u16 u32 u64 int i8 i16 i32 i64) -/** - * - * The `Index` trait is used to specify the functionality of indexing operations - * like `arr[idx]` when used in an immutable context. - * - * # Example - * - * A trivial implementation of `Index`. When `Foo[Foo]` happens, it ends up - * calling `index`, and therefore, `main` prints `Indexing!`. - * - * ``` - * struct Foo; - * - * impl Index<Foo, Foo> for Foo { - * fn index<'a>(&'a self, _index: &Foo) -> &'a Foo { - * println!("Indexing!"); - * self - * } - * } - * - * fn main() { - * Foo[Foo]; - * } - * ``` - */ +/// The `Index` trait is used to specify the functionality of indexing operations +/// like `arr[idx]` when used in an immutable context. +/// +/// # Example +/// +/// A trivial implementation of `Index`. When `Foo[Foo]` happens, it ends up +/// calling `index`, and therefore, `main` prints `Indexing!`. +/// +/// ``` +/// struct Foo; +/// +/// impl Index<Foo, Foo> for Foo { +/// fn index<'a>(&'a self, _index: &Foo) -> &'a Foo { +/// println!("Indexing!"); +/// self +/// } +/// } +/// +/// fn main() { +/// Foo[Foo]; +/// } +/// ``` #[lang="index"] pub trait Index<Sized? Index, Sized? Result> for Sized? { /// The method for the indexing (`Foo[Bar]`) operation fn index<'a>(&'a self, index: &Index) -> &'a Result; } -/** - * - * The `IndexMut` trait is used to specify the functionality of indexing - * operations like `arr[idx]`, when used in a mutable context. - * - * # Example - * - * A trivial implementation of `IndexMut`. When `Foo[Foo]` happens, it ends up - * calling `index_mut`, and therefore, `main` prints `Indexing!`. - * - * ``` - * struct Foo; - * - * impl IndexMut<Foo, Foo> for Foo { - * fn index_mut<'a>(&'a mut self, _index: &Foo) -> &'a mut Foo { - * println!("Indexing!"); - * self - * } - * } - * - * fn main() { - * &mut Foo[Foo]; - * } - * ``` - */ +/// The `IndexMut` trait is used to specify the functionality of indexing +/// operations like `arr[idx]`, when used in a mutable context. +/// +/// # Example +/// +/// A trivial implementation of `IndexMut`. When `Foo[Foo]` happens, it ends up +/// calling `index_mut`, and therefore, `main` prints `Indexing!`. +/// +/// ``` +/// struct Foo; +/// +/// impl IndexMut<Foo, Foo> for Foo { +/// fn index_mut<'a>(&'a mut self, _index: &Foo) -> &'a mut Foo { +/// println!("Indexing!"); +/// self +/// } +/// } +/// +/// fn main() { +/// &mut Foo[Foo]; +/// } +/// ``` #[lang="index_mut"] pub trait IndexMut<Sized? Index, Sized? Result> for Sized? { /// The method for the indexing (`Foo[Bar]`) operation fn index_mut<'a>(&'a mut self, index: &Index) -> &'a mut Result; } -/** - * - * The `Slice` trait is used to specify the functionality of slicing operations - * like `arr[from..to]` when used in an immutable context. - * - * # Example - * - * A trivial implementation of `Slice`. When `Foo[..Foo]` happens, it ends up - * calling `slice_to`, and therefore, `main` prints `Slicing!`. - * - * ```ignore - * struct Foo; - * - * impl Slice<Foo, Foo> for Foo { - * fn as_slice_<'a>(&'a self) -> &'a Foo { - * println!("Slicing!"); - * self - * } - * fn slice_from_or_fail<'a>(&'a self, _from: &Foo) -> &'a Foo { - * println!("Slicing!"); - * self - * } - * fn slice_to_or_fail<'a>(&'a self, _to: &Foo) -> &'a Foo { - * println!("Slicing!"); - * self - * } - * fn slice_or_fail<'a>(&'a self, _from: &Foo, _to: &Foo) -> &'a Foo { - * println!("Slicing!"); - * self - * } - * } - * - * fn main() { - * Foo[..Foo]; - * } - * ``` - */ +/// The `Slice` trait is used to specify the functionality of slicing operations +/// like `arr[from..to]` when used in an immutable context. +/// +/// # Example +/// +/// A trivial implementation of `Slice`. When `Foo[..Foo]` happens, it ends up +/// calling `slice_to`, and therefore, `main` prints `Slicing!`. +/// +/// ```ignore +/// struct Foo; +/// +/// impl Slice<Foo, Foo> for Foo { +/// fn as_slice_<'a>(&'a self) -> &'a Foo { +/// println!("Slicing!"); +/// self +/// } +/// fn slice_from_or_fail<'a>(&'a self, _from: &Foo) -> &'a Foo { +/// println!("Slicing!"); +/// self +/// } +/// fn slice_to_or_fail<'a>(&'a self, _to: &Foo) -> &'a Foo { +/// println!("Slicing!"); +/// self +/// } +/// fn slice_or_fail<'a>(&'a self, _from: &Foo, _to: &Foo) -> &'a Foo { +/// println!("Slicing!"); +/// self +/// } +/// } +/// +/// fn main() { +/// Foo[..Foo]; +/// } +/// ``` #[lang="slice"] pub trait Slice<Sized? Idx, Sized? Result> for Sized? { /// The method for the slicing operation foo[] @@ -723,43 +671,40 @@ pub trait Slice<Sized? Idx, Sized? Result> for Sized? { fn slice_or_fail<'a>(&'a self, from: &Idx, to: &Idx) -> &'a Result; } -/** - * - * The `SliceMut` trait is used to specify the functionality of slicing - * operations like `arr[from..to]`, when used in a mutable context. - * - * # Example - * - * A trivial implementation of `SliceMut`. When `Foo[Foo..]` happens, it ends up - * calling `slice_from_mut`, and therefore, `main` prints `Slicing!`. - * - * ```ignore - * struct Foo; - * - * impl SliceMut<Foo, Foo> for Foo { - * fn as_mut_slice_<'a>(&'a mut self) -> &'a mut Foo { - * println!("Slicing!"); - * self - * } - * fn slice_from_or_fail_mut<'a>(&'a mut self, _from: &Foo) -> &'a mut Foo { - * println!("Slicing!"); - * self - * } - * fn slice_to_or_fail_mut<'a>(&'a mut self, _to: &Foo) -> &'a mut Foo { - * println!("Slicing!"); - * self - * } - * fn slice_or_fail_mut<'a>(&'a mut self, _from: &Foo, _to: &Foo) -> &'a mut Foo { - * println!("Slicing!"); - * self - * } - * } - * - * pub fn main() { - * Foo[mut Foo..]; - * } - * ``` - */ +/// The `SliceMut` trait is used to specify the functionality of slicing +/// operations like `arr[from..to]`, when used in a mutable context. +/// +/// # Example +/// +/// A trivial implementation of `SliceMut`. When `Foo[Foo..]` happens, it ends up +/// calling `slice_from_mut`, and therefore, `main` prints `Slicing!`. +/// +/// ```ignore +/// struct Foo; +/// +/// impl SliceMut<Foo, Foo> for Foo { +/// fn as_mut_slice_<'a>(&'a mut self) -> &'a mut Foo { +/// println!("Slicing!"); +/// self +/// } +/// fn slice_from_or_fail_mut<'a>(&'a mut self, _from: &Foo) -> &'a mut Foo { +/// println!("Slicing!"); +/// self +/// } +/// fn slice_to_or_fail_mut<'a>(&'a mut self, _to: &Foo) -> &'a mut Foo { +/// println!("Slicing!"); +/// self +/// } +/// fn slice_or_fail_mut<'a>(&'a mut self, _from: &Foo, _to: &Foo) -> &'a mut Foo { +/// println!("Slicing!"); +/// self +/// } +/// } +/// +/// pub fn main() { +/// Foo[mut Foo..]; +/// } +/// ``` #[lang="slice_mut"] pub trait SliceMut<Sized? Idx, Sized? Result> for Sized? { /// The method for the slicing operation foo[] @@ -772,33 +717,30 @@ pub trait SliceMut<Sized? Idx, Sized? Result> for Sized? { fn slice_or_fail_mut<'a>(&'a mut self, from: &Idx, to: &Idx) -> &'a mut Result; } -/** - * - * The `Deref` trait is used to specify the functionality of dereferencing - * operations like `*v`. - * - * # Example - * - * A struct with a single field which is accessible via dereferencing the - * struct. - * - * ``` - * struct DerefExample<T> { - * value: T - * } - * - * impl<T> Deref<T> for DerefExample<T> { - * fn deref<'a>(&'a self) -> &'a T { - * &self.value - * } - * } - * - * fn main() { - * let x = DerefExample { value: 'a' }; - * assert_eq!('a', *x); - * } - * ``` - */ +/// The `Deref` trait is used to specify the functionality of dereferencing +/// operations like `*v`. +/// +/// # Example +/// +/// A struct with a single field which is accessible via dereferencing the +/// struct. +/// +/// ``` +/// struct DerefExample<T> { +/// value: T +/// } +/// +/// impl<T> Deref<T> for DerefExample<T> { +/// fn deref<'a>(&'a self) -> &'a T { +/// &self.value +/// } +/// } +/// +/// fn main() { +/// let x = DerefExample { value: 'a' }; +/// assert_eq!('a', *x); +/// } +/// ``` #[lang="deref"] pub trait Deref<Sized? Result> for Sized? { /// The method called to dereference a value @@ -813,40 +755,37 @@ impl<'a, Sized? T> Deref<T> for &'a mut T { fn deref(&self) -> &T { *self } } -/** - * - * The `DerefMut` trait is used to specify the functionality of dereferencing - * mutably like `*v = 1;` - * - * # Example - * - * A struct with a single field which is modifiable via dereferencing the - * struct. - * - * ``` - * struct DerefMutExample<T> { - * value: T - * } - * - * impl<T> Deref<T> for DerefMutExample<T> { - * fn deref<'a>(&'a self) -> &'a T { - * &self.value - * } - * } - * - * impl<T> DerefMut<T> for DerefMutExample<T> { - * fn deref_mut<'a>(&'a mut self) -> &'a mut T { - * &mut self.value - * } - * } - * - * fn main() { - * let mut x = DerefMutExample { value: 'a' }; - * *x = 'b'; - * assert_eq!('b', *x); - * } - * ``` - */ +/// The `DerefMut` trait is used to specify the functionality of dereferencing +/// mutably like `*v = 1;` +/// +/// # Example +/// +/// A struct with a single field which is modifiable via dereferencing the +/// struct. +/// +/// ``` +/// struct DerefMutExample<T> { +/// value: T +/// } +/// +/// impl<T> Deref<T> for DerefMutExample<T> { +/// fn deref<'a>(&'a self) -> &'a T { +/// &self.value +/// } +/// } +/// +/// impl<T> DerefMut<T> for DerefMutExample<T> { +/// fn deref_mut<'a>(&'a mut self) -> &'a mut T { +/// &mut self.value +/// } +/// } +/// +/// fn main() { +/// let mut x = DerefMutExample { value: 'a' }; +/// *x = 'b'; +/// assert_eq!('b', *x); +/// } +/// ``` #[lang="deref_mut"] pub trait DerefMut<Sized? Result>: Deref<Result> { /// The method called to mutably dereference a value diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index 36464e4d29e..950f04a5d97 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -34,8 +34,6 @@ // * The `raw` and `bytes` submodules. // * Boilerplate trait implementations. -pub use self::BinarySearchResult::*; - use mem::transmute; use clone::Clone; use cmp::{PartialEq, PartialOrd, Eq, Ord, Ordering, Less, Equal, Greater, Equiv}; @@ -219,7 +217,7 @@ pub trait SlicePrelude<T> for Sized? { /// found; the fourth could match any position in `[1,4]`. /// /// ```rust - /// use std::slice::{Found, NotFound}; + /// use std::slice::BinarySearchResult::{Found, NotFound}; /// let s = [0i, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]; /// let s = s.as_slice(); /// @@ -548,7 +546,7 @@ impl<T> SlicePrelude<T> for [T] { while lim != 0 { let ix = base + (lim >> 1); match f(&self[ix]) { - Equal => return Found(ix), + Equal => return BinarySearchResult::Found(ix), Less => { base = ix + 1; lim -= 1; @@ -557,7 +555,7 @@ impl<T> SlicePrelude<T> for [T] { } lim >>= 1; } - return NotFound(base); + return BinarySearchResult::NotFound(base); } #[inline] @@ -838,7 +836,7 @@ pub trait OrdSlicePrelude<T: Ord> for Sized? { /// found; the fourth could match any position in `[1,4]`. /// /// ```rust - /// use std::slice::{Found, NotFound}; + /// use std::slice::BinarySearchResult::{Found, NotFound}; /// let s = [0i, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]; /// let s = s.as_slice(); /// @@ -1613,8 +1611,8 @@ impl BinarySearchResult { /// Similar to `Result::ok`. pub fn found(&self) -> Option<uint> { match *self { - Found(i) => Some(i), - NotFound(_) => None + BinarySearchResult::Found(i) => Some(i), + BinarySearchResult::NotFound(_) => None } } @@ -1622,8 +1620,8 @@ impl BinarySearchResult { /// Similar to `Result::err`. pub fn not_found(&self) -> Option<uint> { match *self { - Found(_) => None, - NotFound(i) => Some(i) + BinarySearchResult::Found(_) => None, + BinarySearchResult::NotFound(i) => Some(i) } } } @@ -1634,9 +1632,7 @@ impl BinarySearchResult { // Free functions // -/** - * Converts a pointer to A into a slice of length 1 (without copying). - */ +/// Converts a pointer to A into a slice of length 1 (without copying). #[unstable = "waiting for DST"] pub fn ref_slice<'a, A>(s: &'a A) -> &'a [A] { unsafe { @@ -1644,9 +1640,7 @@ pub fn ref_slice<'a, A>(s: &'a A) -> &'a [A] { } } -/** - * Converts a pointer to A into a slice of length 1 (without copying). - */ +/// Converts a pointer to A into a slice of length 1 (without copying). #[unstable = "waiting for DST"] pub fn mut_ref_slice<'a, A>(s: &'a mut A) -> &'a mut [A] { unsafe { @@ -1710,10 +1704,8 @@ pub mod raw { use raw::Slice; use option::{None, Option, Some}; - /** - * Form a slice from a pointer and length (as a number of units, - * not bytes). - */ + /// Form a slice from a pointer and length (as a number of units, + /// not bytes). #[inline] #[deprecated = "renamed to slice::from_raw_buf"] pub unsafe fn buf_as_slice<T,U>(p: *const T, len: uint, f: |v: &[T]| -> U) @@ -1724,10 +1716,8 @@ pub mod raw { })) } - /** - * Form a slice from a pointer and length (as a number of units, - * not bytes). - */ + /// Form a slice from a pointer and length (as a number of units, + /// not bytes). #[inline] #[deprecated = "renamed to slice::from_raw_mut_buf"] pub unsafe fn mut_buf_as_slice<T, @@ -1742,12 +1732,10 @@ pub mod raw { })) } - /** - * Returns a pointer to first element in slice and adjusts - * slice so it no longer contains that element. Returns None - * if the slice is empty. O(1). - */ - #[inline] + /// Returns a pointer to first element in slice and adjusts + /// slice so it no longer contains that element. Returns None + /// if the slice is empty. O(1). + #[inline] #[deprecated = "inspect `Slice::{data, len}` manually (increment data by 1)"] pub unsafe fn shift_ptr<T>(slice: &mut Slice<T>) -> Option<*const T> { if slice.len == 0 { return None; } @@ -1757,11 +1745,9 @@ pub mod raw { Some(head) } - /** - * Returns a pointer to last element in slice and adjusts - * slice so it no longer contains that element. Returns None - * if the slice is empty. O(1). - */ + /// Returns a pointer to last element in slice and adjusts + /// slice so it no longer contains that element. Returns None + /// if the slice is empty. O(1). #[inline] #[deprecated = "inspect `Slice::{data, len}` manually (decrement len by 1)"] pub unsafe fn pop_ptr<T>(slice: &mut Slice<T>) -> Option<*const T> { |
