@@ -722,3 +722,120 @@ mod prim_isize { }
722
722
///
723
723
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
724
724
mod prim_usize { }
725
+
726
+ #[ doc( primitive = "reference" ) ]
727
+ //
728
+ /// References, both shared and mutable.
729
+ ///
730
+ /// A reference represents a borrow of some owned value. You can get one by using the `&` or `&mut`
731
+ /// operators on a value, or by using a `ref` or `ref mut` pattern.
732
+ ///
733
+ /// For those familiar with pointers, a reference is just a pointer that is assumed to not be null.
734
+ /// In fact, `Option<&T>` has the same memory representation as a nullable pointer, and can be
735
+ /// passed across FFI boundaries as such.
736
+ ///
737
+ /// In most cases, references can be used much like the original value. Field access, method
738
+ /// calling, and indexing work the same (save for mutability rules, of course). In addition, the
739
+ /// comparison operators transparently defer to the referent's implementation, allowing references
740
+ /// to be compared the same as owned values.
741
+ ///
742
+ /// References have a lifetime attached to them, which represents the scope for which the borrow is
743
+ /// valid. A lifetime is said to "outlive" another one if its representative scope is as long or
744
+ /// longer than the other. The `'static` lifetime is the longest lifetime, which represents the
745
+ /// total life of the program. For example, string literals have a `'static` lifetime because the
746
+ /// text data is embedded into the binary of the program, rather than in an allocation that needs
747
+ /// to be dynamically managed.
748
+ ///
749
+ /// `&mut T` references can be freely coerced into `&T` references with the same referent type, and
750
+ /// references with longer lifetimes can be freely coerced into references with shorter ones.
751
+ ///
752
+ /// For more information on how to use references, see [the book's section on "References and
753
+ /// Borrowing"][book-refs].
754
+ ///
755
+ /// [book-refs]: ../book/second-edition/ch04-02-references-and-borrowing.html
756
+ ///
757
+ /// The following traits are implemented for all `&T`, regardless of the type of its referent:
758
+ ///
759
+ /// * [`Copy`]
760
+ /// * [`Clone`] \(Note that this will not defer to `T`'s `Clone` implementation if it exists!)
761
+ /// * [`Deref`]
762
+ /// * [`Borrow`]
763
+ /// * [`Pointer`]
764
+ ///
765
+ /// [`Copy`]: marker/trait.Copy.html
766
+ /// [`Clone`]: clone/trait.Clone.html
767
+ /// [`Deref`]: ops/trait.Deref.html
768
+ /// [`Borrow`]: borrow/trait.Borrow.html
769
+ /// [`Pointer`]: fmt/trait.Pointer.html
770
+ ///
771
+ /// `&mut T` references get all of the above except `Copy` and `Clone` (to prevent creating
772
+ /// multiple simultaneous mutable borrows), plus the following, regardless of the type of its
773
+ /// referent:
774
+ ///
775
+ /// * [`DerefMut`]
776
+ /// * [`BorrowMut`]
777
+ ///
778
+ /// [`DerefMut`]: ops/trait.DerefMut.html
779
+ /// [`BorrowMut`]: borrow/trait.BorrowMut.html
780
+ ///
781
+ /// The following traits are implemented on `&T` references if the underlying `T` also implements
782
+ /// that trait:
783
+ ///
784
+ /// * All the traits in [`std::fmt`] except [`Pointer`] and [`fmt::Write`]
785
+ /// * [`PartialOrd`]
786
+ /// * [`Ord`]
787
+ /// * [`PartialEq`]
788
+ /// * [`Eq`]
789
+ /// * [`AsRef`]
790
+ /// * [`Fn`] \(in addition, `&T` references get [`FnMut`] and [`FnOnce`] if `T: Fn`)
791
+ /// * [`Hash`]
792
+ /// * [`ToSocketAddrs`]
793
+ ///
794
+ /// [`std::fmt`]: fmt/index.html
795
+ /// [`fmt::Write`]: fmt/trait.Write.html
796
+ /// [`PartialOrd`]: cmp/trait.PartialOrd.html
797
+ /// [`Ord`]: cmp/trait.Ord.html
798
+ /// [`PartialEq`]: cmp/trait.PartialEq.html
799
+ /// [`Eq`]: cmp/trait.Eq.html
800
+ /// [`AsRef`]: convert/trait.AsRef.html
801
+ /// [`Fn`]: ops/trait.Fn.html
802
+ /// [`FnMut`]: ops/trait.FnMut.html
803
+ /// [`FnOnce`]: ops/trait.FnOnce.html
804
+ /// [`Hash`]: hash/trait.Hash.html
805
+ /// [`ToSocketAddrs`]: net/trait.ToSocketAddrs.html
806
+ ///
807
+ /// `&mut T` references get all of the above except `ToSocketAddrs`, plus the following, if `T`
808
+ /// implements that trait:
809
+ ///
810
+ /// * [`AsMut`]
811
+ /// * [`FnMut`] \(in addition, `&mut T` references get [`FnOnce`] if `T: FnMut`)
812
+ /// * [`fmt::Write`]
813
+ /// * [`Iterator`]
814
+ /// * [`DoubleEndedIterator`]
815
+ /// * [`ExactSizeIterator`]
816
+ /// * [`FusedIterator`]
817
+ /// * [`TrustedLen`]
818
+ /// * [`Send`] \(note that `&T` references only get `Send` if `T: Sync`)
819
+ /// * [`io::Write`]
820
+ /// * [`Read`]
821
+ /// * [`Seek`]
822
+ /// * [`BufRead`]
823
+ ///
824
+ /// [`AsMut`]: convert/trait.AsMut.html
825
+ /// [`Iterator`]: iter/trait.Iterator.html
826
+ /// [`DoubleEndedIterator`]: iter/trait.DoubleEndedIterator.html
827
+ /// [`ExactSizeIterator`]: iter/trait.ExactSizeIterator.html
828
+ /// [`FusedIterator`]: iter/trait.FusedIterator.html
829
+ /// [`TrustedLen`]: iter/trait.TrustedLen.html
830
+ /// [`Send`]: marker/trait.Send.html
831
+ /// [`io::Write`]: io/trait.Write.html
832
+ /// [`Read`]: io/trait.Read.html
833
+ /// [`Seek`]: io/trait.Seek.html
834
+ /// [`BufRead`]: io/trait.BufRead.html
835
+ ///
836
+ /// Note that due to method call deref coercion, simply calling a trait method will act like they
837
+ /// work on references as well as they do on owned values! The implementations described here are
838
+ /// meant for generic contexts, where the final type `T` is a type parameter or otherwise not
839
+ /// locally known.
840
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
841
+ mod prim_ref { }
0 commit comments