88// option. This file may not be copied, modified, or distributed
99// except according to those terms.
1010
11- // So we don't have to document the actual methods on the traits.
12- #[ allow( missing_doc) ] ;
13-
1411/*!
1512 *
1613 * Traits representing built-in operators, useful for overloading
8380 */
8481#[ lang="drop" ]
8582pub trait Drop {
83+ /// The `drop` method, called when the value goes out of scope.
8684 fn drop ( & mut self ) ;
8785}
8886
@@ -112,6 +110,7 @@ pub trait Drop {
112110 */
113111#[ lang="add" ]
114112pub trait Add < RHS , Result > {
113+ /// The method for the `+` operator
115114 fn add ( & self , rhs : & RHS ) -> Result ;
116115}
117116
@@ -141,6 +140,7 @@ pub trait Add<RHS,Result> {
141140 */
142141#[ lang="sub" ]
143142pub trait Sub < RHS , Result > {
143+ /// The method for the `-` operator
144144 fn sub ( & self , rhs : & RHS ) -> Result ;
145145}
146146
@@ -170,6 +170,7 @@ pub trait Sub<RHS,Result> {
170170 */
171171#[ lang="mul" ]
172172pub trait Mul < RHS , Result > {
173+ /// The method for the `*` operator
173174 fn mul ( & self , rhs : & RHS ) -> Result ;
174175}
175176
@@ -199,6 +200,7 @@ pub trait Mul<RHS,Result> {
199200 */
200201#[ lang="div" ]
201202pub trait Div < RHS , Result > {
203+ /// The method for the `/` operator
202204 fn div ( & self , rhs : & RHS ) -> Result ;
203205}
204206
@@ -228,6 +230,7 @@ pub trait Div<RHS,Result> {
228230 */
229231#[ lang="rem" ]
230232pub trait Rem < RHS , Result > {
233+ /// The method for the `%` operator
231234 fn rem ( & self , rhs : & RHS ) -> Result ;
232235}
233236
@@ -257,6 +260,7 @@ pub trait Rem<RHS,Result> {
257260 */
258261#[ lang="neg" ]
259262pub trait Neg < Result > {
263+ /// The method for the unary `-` operator
260264 fn neg ( & self ) -> Result ;
261265}
262266
@@ -286,6 +290,7 @@ pub trait Neg<Result> {
286290 */
287291#[ lang="not" ]
288292pub trait Not < Result > {
293+ /// The method for the unary `!` operator
289294 fn not ( & self ) -> Result ;
290295}
291296
@@ -315,6 +320,7 @@ pub trait Not<Result> {
315320 */
316321#[ lang="bitand" ]
317322pub trait BitAnd < RHS , Result > {
323+ /// The method for the `&` operator
318324 fn bitand ( & self , rhs : & RHS ) -> Result ;
319325}
320326
@@ -344,6 +350,7 @@ pub trait BitAnd<RHS,Result> {
344350 */
345351#[ lang="bitor" ]
346352pub trait BitOr < RHS , Result > {
353+ /// The method for the `|` operator
347354 fn bitor ( & self , rhs : & RHS ) -> Result ;
348355}
349356
@@ -373,6 +380,7 @@ pub trait BitOr<RHS,Result> {
373380 */
374381#[ lang="bitxor" ]
375382pub trait BitXor < RHS , Result > {
383+ /// The method for the `^` operator
376384 fn bitxor ( & self , rhs : & RHS ) -> Result ;
377385}
378386
@@ -402,6 +410,7 @@ pub trait BitXor<RHS,Result> {
402410 */
403411#[ lang="shl" ]
404412pub trait Shl < RHS , Result > {
413+ /// The method for the `<<` operator
405414 fn shl ( & self , rhs : & RHS ) -> Result ;
406415}
407416
@@ -431,6 +440,7 @@ pub trait Shl<RHS,Result> {
431440 */
432441#[ lang="shr" ]
433442pub trait Shr < RHS , Result > {
443+ /// The method for the `>>` operator
434444 fn shr ( & self , rhs : & RHS ) -> Result ;
435445}
436446
@@ -461,6 +471,7 @@ pub trait Shr<RHS,Result> {
461471 */
462472#[ lang="index" ]
463473pub trait Index < Index , Result > {
474+ /// The method for the indexing (`Foo[Bar]`) operation
464475 fn index ( & self , index : & Index ) -> Result ;
465476}
466477
@@ -469,9 +480,37 @@ pub trait Deref<Result> {
469480 fn deref < ' a > ( & ' a self ) -> & ' a Result ;
470481}
471482
483+ /**
484+ *
485+ * The `Deref` trait is used to specify the functionality of dereferencing
486+ * operations like `*v`.
487+ *
488+ * # Example
489+ *
490+ * A struct with a single field which is accessible via dereferencing the
491+ * struct.
492+ *
493+ * ```
494+ * struct DerefExample<T> {
495+ * value: T
496+ * }
497+ *
498+ * impl<T> Deref<T> for DerefExample<T> {
499+ * fn deref<'a>(&'a self) -> &'a T {
500+ * &self.value
501+ * }
502+ * }
503+ *
504+ * fn main() {
505+ * let x = DerefExample { value: 'a' };
506+ * assert_eq!('a', *x);
507+ * }
508+ * ```
509+ */
472510#[ cfg( not( stage0) ) ]
473511#[ lang="deref" ]
474512pub trait Deref < Result > {
513+ /// The method called to dereference a value
475514 fn deref < ' a > ( & ' a self ) -> & ' a Result ;
476515}
477516
@@ -480,9 +519,44 @@ pub trait DerefMut<Result>: Deref<Result> {
480519 fn deref_mut < ' a > ( & ' a mut self ) -> & ' a mut Result ;
481520}
482521
522+ /**
523+ *
524+ * The `DerefMut` trait is used to specify the functionality of dereferencing
525+ * mutably like `*v = 1;`
526+ *
527+ * # Example
528+ *
529+ * A struct with a single field which is modifiable via dereferencing the
530+ * struct.
531+ *
532+ * ```
533+ * struct DerefMutExample<T> {
534+ * value: T
535+ * }
536+ *
537+ * impl<T> Deref<T> for DerefMutExample<T> {
538+ * fn deref<'a>(&'a self) -> &'a T {
539+ * &self.value
540+ * }
541+ * }
542+ *
543+ * impl<T> DerefMut<T> for DerefMutExample<T> {
544+ * fn deref_mut<'a>(&'a mut self) -> &'a mut T {
545+ * &mut self.value
546+ * }
547+ * }
548+ *
549+ * fn main() {
550+ * let mut x = DerefMutExample { value: 'a' };
551+ * *x = 'b';
552+ * assert_eq!('b', *x);
553+ * }
554+ * ```
555+ */
483556#[ cfg( not( stage0) ) ]
484557#[ lang="deref_mut" ]
485558pub trait DerefMut < Result > : Deref < Result > {
559+ /// The method called to mutably dereference a value
486560 fn deref_mut < ' a > ( & ' a mut self ) -> & ' a mut Result ;
487561}
488562
0 commit comments