From 6e27bd8c0168c88f41866a6af75c2de08cbdb349 Mon Sep 17 00:00:00 2001 From: projektir Date: Mon, 22 May 2017 21:59:42 -0400 Subject: [PATCH] Adding links to option::Option --- src/libcore/option.rs | 86 ++++++++++++++++++++++++++++++------------- 1 file changed, 60 insertions(+), 26 deletions(-) diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 515f49d6f0b..e825acad471 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -174,7 +174,7 @@ impl Option { // Querying the contained values ///////////////////////////////////////////////////////////////////////// - /// Returns `true` if the option is a `Some` value. + /// Returns `true` if the option is a [`Some`] value. /// /// # Examples /// @@ -185,6 +185,8 @@ impl Option { /// let x: Option = None; /// assert_eq!(x.is_some(), false); /// ``` + /// + /// [`Some`]: #variant.Some #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn is_some(&self) -> bool { @@ -194,7 +196,7 @@ pub fn is_some(&self) -> bool { } } - /// Returns `true` if the option is a `None` value. + /// Returns `true` if the option is a [`None`] value. /// /// # Examples /// @@ -205,6 +207,8 @@ pub fn is_some(&self) -> bool { /// let x: Option = None; /// assert_eq!(x.is_none(), true); /// ``` + /// + /// [`None`]: #variant.None #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn is_none(&self) -> bool { @@ -269,13 +273,14 @@ pub fn as_mut(&mut self) -> Option<&mut T> { // Getting to contained values ///////////////////////////////////////////////////////////////////////// - /// Unwraps an option, yielding the content of a `Some`. + /// Unwraps an option, yielding the content of a [`Some`]. /// /// # Panics /// /// Panics if the value is a [`None`] with a custom panic message provided by /// `msg`. /// + /// [`Some`]: #variant.Some /// [`None`]: #variant.None /// /// # Examples @@ -298,16 +303,17 @@ pub fn expect(self, msg: &str) -> T { } } - /// Moves the value `v` out of the `Option` if it is `Some(v)`. + /// Moves the value `v` out of the `Option` if it is [`Some(v)`]. /// /// In general, because this function may panic, its use is discouraged. - /// Instead, prefer to use pattern matching and handle the `None` + /// Instead, prefer to use pattern matching and handle the [`None`] /// case explicitly. /// /// # Panics /// /// Panics if the self value equals [`None`]. /// + /// [`Some(v)`]: #variant.Some /// [`None`]: #variant.None /// /// # Examples @@ -395,7 +401,9 @@ pub fn map U>(self, f: F) -> Option { } /// Applies a function to the contained value (if any), - /// or returns a `default` (if not). + /// or returns a [`default`][] (if not). + /// + /// [`default`]: ../default/trait.Default.html#tymethod.default /// /// # Examples /// @@ -416,7 +424,9 @@ pub fn map_or U>(self, default: U, f: F) -> U { } /// Applies a function to the contained value (if any), - /// or computes a `default` (if not). + /// or computes a [`default`][] (if not). + /// + /// [`default`]: ../default/trait.Default.html#tymethod.default /// /// # Examples /// @@ -438,12 +448,14 @@ pub fn map_or_else U, F: FnOnce(T) -> U>(self, default: D, f: } } - /// Transforms the `Option` into a [`Result`], mapping `Some(v)` to - /// [`Ok(v)`] and `None` to [`Err(err)`][Err]. + /// Transforms the `Option` into a [`Result`], mapping [`Some(v)`] to + /// [`Ok(v)`] and [`None`] to [`Err(err)`]. /// /// [`Result`]: ../../std/result/enum.Result.html /// [`Ok(v)`]: ../../std/result/enum.Result.html#variant.Ok - /// [Err]: ../../std/result/enum.Result.html#variant.Err + /// [`Err(err)`]: ../../std/result/enum.Result.html#variant.Err + /// [`None`]: #variant.None + /// [`Some(v)`]: #variant.Some /// /// # Examples /// @@ -463,12 +475,14 @@ pub fn ok_or(self, err: E) -> Result { } } - /// Transforms the `Option` into a [`Result`], mapping `Some(v)` to - /// [`Ok(v)`] and `None` to [`Err(err())`][Err]. + /// Transforms the `Option` into a [`Result`], mapping [`Some(v)`] to + /// [`Ok(v)`] and [`None`] to [`Err(err())`]. /// /// [`Result`]: ../../std/result/enum.Result.html /// [`Ok(v)`]: ../../std/result/enum.Result.html#variant.Ok - /// [Err]: ../../std/result/enum.Result.html#variant.Err + /// [`Err(err())`]: ../../std/result/enum.Result.html#variant.Err + /// [`None`]: #variant.None + /// [`Some(v)`]: #variant.Some /// /// # Examples /// @@ -534,7 +548,9 @@ pub fn iter_mut(&mut self) -> IterMut { // Boolean operations on the values, eager and lazy ///////////////////////////////////////////////////////////////////////// - /// Returns `None` if the option is `None`, otherwise returns `optb`. + /// Returns [`None`] if the option is [`None`], otherwise returns `optb`. + /// + /// [`None`]: #variant.None /// /// # Examples /// @@ -564,11 +580,13 @@ pub fn and(self, optb: Option) -> Option { } } - /// Returns `None` if the option is `None`, otherwise calls `f` with the + /// Returns [`None`] if the option is [`None`], otherwise calls `f` with the /// wrapped value and returns the result. /// /// Some languages call this operation flatmap. /// + /// [`None`]: #variant.None + /// /// # Examples /// /// ``` @@ -645,9 +663,11 @@ pub fn or_else Option>(self, f: F) -> Option { // Entry-like operations to insert if None and return a reference ///////////////////////////////////////////////////////////////////////// - /// Inserts `v` into the option if it is `None`, then + /// Inserts `v` into the option if it is [`None`], then /// returns a mutable reference to the contained value. /// + /// [`None`]: #variant.None + /// /// # Examples /// /// ``` @@ -678,9 +698,11 @@ pub fn get_or_insert(&mut self, v: T) -> &mut T { } } - /// Inserts a value computed from `f` into the option if it is `None`, then + /// Inserts a value computed from `f` into the option if it is [`None`], then /// returns a mutable reference to the contained value. /// + /// [`None`]: #variant.None + /// /// # Examples /// /// ``` @@ -715,7 +737,9 @@ pub fn get_or_insert_with T>(&mut self, f: F) -> &mut T { // Misc ///////////////////////////////////////////////////////////////////////// - /// Takes the value out of the option, leaving a `None` in its place. + /// Takes the value out of the option, leaving a [`None`] in its place. + /// + /// [`None`]: #variant.None /// /// # Examples /// @@ -757,16 +781,16 @@ pub fn cloned(self) -> Option { impl Option { /// Returns the contained value or a default /// - /// Consumes the `self` argument then, if `Some`, returns the contained - /// value, otherwise if `None`, returns the default value for that + /// Consumes the `self` argument then, if [`Some`], returns the contained + /// value, otherwise if [`None`], returns the default value for that /// type. /// /// # Examples /// /// Convert a string to an integer, turning poorly-formed strings - /// into 0 (the default value for integers). `parse` converts - /// a string to any other type that implements `FromStr`, returning - /// `None` on error. + /// into 0 (the default value for integers). [`parse`] converts + /// a string to any other type that implements [`FromStr`], returning + /// [`None`] on error. /// /// ``` /// let good_year_from_input = "1909"; @@ -777,6 +801,11 @@ impl Option { /// assert_eq!(1909, good_year); /// assert_eq!(0, bad_year); /// ``` + /// + /// [`Some`]: #variant.Some + /// [`None`]: #variant.None + /// [`parse`]: ../../std/primitive.str.html#method.parse + /// [`FromStr`]: ../../std/str/trait.FromStr.html #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn unwrap_or_default(self) -> T { @@ -801,7 +830,9 @@ fn expect_failed(msg: &str) -> ! { #[stable(feature = "rust1", since = "1.0.0")] impl Default for Option { - /// Returns None. + /// Returns [`None`]. + /// + /// [`None`]: #variant.None #[inline] fn default() -> Option { None } } @@ -1020,8 +1051,8 @@ unsafe impl TrustedLen for IntoIter {} #[stable(feature = "rust1", since = "1.0.0")] impl> FromIterator> for Option { - /// Takes each element in the `Iterator`: if it is `None`, no further - /// elements are taken, and the `None` is returned. Should no `None` occur, a + /// Takes each element in the [`Iterator`]: if it is [`None`], no further + /// elements are taken, and the [`None`] is returned. Should no [`None`] occur, a /// container with the values of each `Option` is returned. /// /// Here is an example which increments every integer in a vector, @@ -1037,6 +1068,9 @@ impl> FromIterator> for Option { /// ).collect(); /// assert!(res == Some(vec![2, 3])); /// ``` + /// + /// [`Iterator`]: ../iter/trait.Iterator.html + /// [`None`]: enum.Option.html#variant.None #[inline] fn from_iter>>(iter: I) -> Option { // FIXME(#11084): This could be replaced with Iterator::scan when this