diff --git a/src/libstd/ops.rs b/src/libstd/ops.rs index 2d5d37e1abc51..49bd95f621def 100644 --- a/src/libstd/ops.rs +++ b/src/libstd/ops.rs @@ -8,9 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// So we don't have to document the actual methods on the traits. -#[allow(missing_doc)]; - /*! * * Traits representing built-in operators, useful for overloading @@ -83,6 +80,7 @@ */ #[lang="drop"] pub trait Drop { + /// The `drop` method, called when the value goes out of scope. fn drop(&mut self); } @@ -112,6 +110,7 @@ pub trait Drop { */ #[lang="add"] pub trait Add { + /// The method for the `+` operator fn add(&self, rhs: &RHS) -> Result; } @@ -141,6 +140,7 @@ pub trait Add { */ #[lang="sub"] pub trait Sub { + /// The method for the `-` operator fn sub(&self, rhs: &RHS) -> Result; } @@ -170,6 +170,7 @@ pub trait Sub { */ #[lang="mul"] pub trait Mul { + /// The method for the `*` operator fn mul(&self, rhs: &RHS) -> Result; } @@ -199,6 +200,7 @@ pub trait Mul { */ #[lang="div"] pub trait Div { + /// The method for the `/` operator fn div(&self, rhs: &RHS) -> Result; } @@ -228,6 +230,7 @@ pub trait Div { */ #[lang="rem"] pub trait Rem { + /// The method for the `%` operator fn rem(&self, rhs: &RHS) -> Result; } @@ -257,6 +260,7 @@ pub trait Rem { */ #[lang="neg"] pub trait Neg { + /// The method for the unary `-` operator fn neg(&self) -> Result; } @@ -286,6 +290,7 @@ pub trait Neg { */ #[lang="not"] pub trait Not { + /// The method for the unary `!` operator fn not(&self) -> Result; } @@ -315,6 +320,7 @@ pub trait Not { */ #[lang="bitand"] pub trait BitAnd { + /// The method for the `&` operator fn bitand(&self, rhs: &RHS) -> Result; } @@ -344,6 +350,7 @@ pub trait BitAnd { */ #[lang="bitor"] pub trait BitOr { + /// The method for the `|` operator fn bitor(&self, rhs: &RHS) -> Result; } @@ -373,6 +380,7 @@ pub trait BitOr { */ #[lang="bitxor"] pub trait BitXor { + /// The method for the `^` operator fn bitxor(&self, rhs: &RHS) -> Result; } @@ -402,6 +410,7 @@ pub trait BitXor { */ #[lang="shl"] pub trait Shl { + /// The method for the `<<` operator fn shl(&self, rhs: &RHS) -> Result; } @@ -431,6 +440,7 @@ pub trait Shl { */ #[lang="shr"] pub trait Shr { + /// The method for the `>>` operator fn shr(&self, rhs: &RHS) -> Result; } @@ -461,6 +471,7 @@ pub trait Shr { */ #[lang="index"] pub trait Index { + /// The method for the indexing (`Foo[Bar]`) operation fn index(&self, index: &Index) -> Result; } @@ -469,9 +480,37 @@ pub trait Deref { fn deref<'a>(&'a self) -> &'a 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 { + * value: T + * } + * + * impl Deref for DerefExample { + * fn deref<'a>(&'a self) -> &'a T { + * &self.value + * } + * } + * + * fn main() { + * let x = DerefExample { value: 'a' }; + * assert_eq!('a', *x); + * } + * ``` + */ #[cfg(not(stage0))] #[lang="deref"] pub trait Deref { + /// The method called to dereference a value fn deref<'a>(&'a self) -> &'a Result; } @@ -480,9 +519,44 @@ pub trait DerefMut: Deref { fn deref_mut<'a>(&'a mut self) -> &'a mut Result; } +/** + * + * 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 { + * value: T + * } + * + * impl Deref for DerefMutExample { + * fn deref<'a>(&'a self) -> &'a T { + * &self.value + * } + * } + * + * impl DerefMut for DerefMutExample { + * 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); + * } + * ``` + */ #[cfg(not(stage0))] #[lang="deref_mut"] pub trait DerefMut: Deref { + /// The method called to mutably dereference a value fn deref_mut<'a>(&'a mut self) -> &'a mut Result; }