149
149
150
150
mod arith;
151
151
mod bit;
152
+ mod deref;
152
153
mod function;
153
154
mod place;
154
155
mod range;
@@ -164,6 +165,9 @@ pub use self::bit::{Not, BitAnd, BitOr, BitXor, Shl, Shr};
164
165
#[ stable( feature = "op_assign_traits" , since = "1.8.0" ) ]
165
166
pub use self :: bit:: { BitAndAssign , BitOrAssign , BitXorAssign , ShlAssign , ShrAssign } ;
166
167
168
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
169
+ pub use self :: deref:: { Deref , DerefMut } ;
170
+
167
171
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
168
172
pub use self :: function:: { Fn , FnMut , FnOnce } ;
169
173
@@ -423,116 +427,6 @@ pub trait IndexMut<Idx: ?Sized>: Index<Idx> {
423
427
fn index_mut ( & mut self , index : Idx ) -> & mut Self :: Output ;
424
428
}
425
429
426
- /// The `Deref` trait is used to specify the functionality of dereferencing
427
- /// operations, like `*v`.
428
- ///
429
- /// `Deref` also enables ['`Deref` coercions'][coercions].
430
- ///
431
- /// [coercions]: ../../book/deref-coercions.html
432
- ///
433
- /// # Examples
434
- ///
435
- /// A struct with a single field which is accessible via dereferencing the
436
- /// struct.
437
- ///
438
- /// ```
439
- /// use std::ops::Deref;
440
- ///
441
- /// struct DerefExample<T> {
442
- /// value: T
443
- /// }
444
- ///
445
- /// impl<T> Deref for DerefExample<T> {
446
- /// type Target = T;
447
- ///
448
- /// fn deref(&self) -> &T {
449
- /// &self.value
450
- /// }
451
- /// }
452
- ///
453
- /// fn main() {
454
- /// let x = DerefExample { value: 'a' };
455
- /// assert_eq!('a', *x);
456
- /// }
457
- /// ```
458
- #[ lang = "deref" ]
459
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
460
- pub trait Deref {
461
- /// The resulting type after dereferencing
462
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
463
- type Target : ?Sized ;
464
-
465
- /// The method called to dereference a value
466
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
467
- fn deref ( & self ) -> & Self :: Target ;
468
- }
469
-
470
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
471
- impl < ' a , T : ?Sized > Deref for & ' a T {
472
- type Target = T ;
473
-
474
- fn deref ( & self ) -> & T { * self }
475
- }
476
-
477
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
478
- impl < ' a , T : ?Sized > Deref for & ' a mut T {
479
- type Target = T ;
480
-
481
- fn deref ( & self ) -> & T { * self }
482
- }
483
-
484
- /// The `DerefMut` trait is used to specify the functionality of dereferencing
485
- /// mutably like `*v = 1;`
486
- ///
487
- /// `DerefMut` also enables ['`Deref` coercions'][coercions].
488
- ///
489
- /// [coercions]: ../../book/deref-coercions.html
490
- ///
491
- /// # Examples
492
- ///
493
- /// A struct with a single field which is modifiable via dereferencing the
494
- /// struct.
495
- ///
496
- /// ```
497
- /// use std::ops::{Deref, DerefMut};
498
- ///
499
- /// struct DerefMutExample<T> {
500
- /// value: T
501
- /// }
502
- ///
503
- /// impl<T> Deref for DerefMutExample<T> {
504
- /// type Target = T;
505
- ///
506
- /// fn deref(&self) -> &T {
507
- /// &self.value
508
- /// }
509
- /// }
510
- ///
511
- /// impl<T> DerefMut for DerefMutExample<T> {
512
- /// fn deref_mut(&mut self) -> &mut T {
513
- /// &mut self.value
514
- /// }
515
- /// }
516
- ///
517
- /// fn main() {
518
- /// let mut x = DerefMutExample { value: 'a' };
519
- /// *x = 'b';
520
- /// assert_eq!('b', *x);
521
- /// }
522
- /// ```
523
- #[ lang = "deref_mut" ]
524
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
525
- pub trait DerefMut : Deref {
526
- /// The method called to mutably dereference a value
527
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
528
- fn deref_mut ( & mut self ) -> & mut Self :: Target ;
529
- }
530
-
531
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
532
- impl < ' a , T : ?Sized > DerefMut for & ' a mut T {
533
- fn deref_mut ( & mut self ) -> & mut T { * self }
534
- }
535
-
536
430
/// Trait that indicates that this is a pointer or a wrapper for one,
537
431
/// where unsizing can be performed on the pointee.
538
432
///
0 commit comments