@@ -244,9 +244,12 @@ use fmt;
244
244
use iter:: { FromIterator , FusedIterator , TrustedLen } ;
245
245
use ops;
246
246
247
- /// `Result` is a type that represents either success (`Ok`) or failure (`Err`).
247
+ /// `Result` is a type that represents either success ([ `Ok`] ) or failure ([ `Err`] ).
248
248
///
249
249
/// See the [`std::result`](index.html) module documentation for details.
250
+ ///
251
+ /// [`Ok`]: enum.Result.html#variant.Ok
252
+ /// [`Err`]: enum.Result.html#variant.Err
250
253
#[ derive( Clone , Copy , PartialEq , PartialOrd , Eq , Ord , Debug , Hash ) ]
251
254
#[ must_use]
252
255
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -269,7 +272,9 @@ impl<T, E> Result<T, E> {
269
272
// Querying the contained values
270
273
/////////////////////////////////////////////////////////////////////////
271
274
272
- /// Returns `true` if the result is `Ok`.
275
+ /// Returns `true` if the result is [`Ok`].
276
+ ///
277
+ /// [`Ok`]: enum.Result.html#variant.Ok
273
278
///
274
279
/// # Examples
275
280
///
@@ -291,7 +296,9 @@ impl<T, E> Result<T, E> {
291
296
}
292
297
}
293
298
294
- /// Returns `true` if the result is `Err`.
299
+ /// Returns `true` if the result is [`Err`].
300
+ ///
301
+ /// [`Err`]: enum.Result.html#variant.Err
295
302
///
296
303
/// # Examples
297
304
///
@@ -433,10 +440,13 @@ impl<T, E> Result<T, E> {
433
440
/////////////////////////////////////////////////////////////////////////
434
441
435
442
/// Maps a `Result<T, E>` to `Result<U, E>` by applying a function to a
436
- /// contained `Ok` value, leaving an `Err` value untouched.
443
+ /// contained [ `Ok`] value, leaving an [ `Err`] value untouched.
437
444
///
438
445
/// This function can be used to compose the results of two functions.
439
446
///
447
+ /// [`Ok`]: enum.Result.html#variant.Ok
448
+ /// [`Err`]: enum.Result.html#variant.Err
449
+ ///
440
450
/// # Examples
441
451
///
442
452
/// Print the numbers on each line of a string multiplied by two.
@@ -461,11 +471,14 @@ impl<T, E> Result<T, E> {
461
471
}
462
472
463
473
/// Maps a `Result<T, E>` to `Result<T, F>` by applying a function to a
464
- /// contained `Err` value, leaving an `Ok` value untouched.
474
+ /// contained [ `Err`] value, leaving an [ `Ok`] value untouched.
465
475
///
466
476
/// This function can be used to pass through a successful result while handling
467
477
/// an error.
468
478
///
479
+ /// [`Ok`]: enum.Result.html#variant.Ok
480
+ /// [`Err`]: enum.Result.html#variant.Err
481
+ ///
469
482
/// # Examples
470
483
///
471
484
/// Basic usage:
@@ -546,7 +559,10 @@ impl<T, E> Result<T, E> {
546
559
// Boolean operations on the values, eager and lazy
547
560
/////////////////////////////////////////////////////////////////////////
548
561
549
- /// Returns `res` if the result is `Ok`, otherwise returns the `Err` value of `self`.
562
+ /// Returns `res` if the result is [`Ok`], otherwise returns the [`Err`] value of `self`.
563
+ ///
564
+ /// [`Ok`]: enum.Result.html#variant.Ok
565
+ /// [`Err`]: enum.Result.html#variant.Err
550
566
///
551
567
/// # Examples
552
568
///
@@ -578,7 +594,10 @@ impl<T, E> Result<T, E> {
578
594
}
579
595
}
580
596
581
- /// Calls `op` if the result is `Ok`, otherwise returns the `Err` value of `self`.
597
+ /// Calls `op` if the result is [`Ok`], otherwise returns the [`Err`] value of `self`.
598
+ ///
599
+ /// [`Ok`]: enum.Result.html#variant.Ok
600
+ /// [`Err`]: enum.Result.html#variant.Err
582
601
///
583
602
/// This function can be used for control flow based on `Result` values.
584
603
///
@@ -604,7 +623,10 @@ impl<T, E> Result<T, E> {
604
623
}
605
624
}
606
625
607
- /// Returns `res` if the result is `Err`, otherwise returns the `Ok` value of `self`.
626
+ /// Returns `res` if the result is [`Err`], otherwise returns the [`Ok`] value of `self`.
627
+ ///
628
+ /// [`Ok`]: enum.Result.html#variant.Ok
629
+ /// [`Err`]: enum.Result.html#variant.Err
608
630
///
609
631
/// # Examples
610
632
///
@@ -636,10 +658,13 @@ impl<T, E> Result<T, E> {
636
658
}
637
659
}
638
660
639
- /// Calls `op` if the result is `Err`, otherwise returns the `Ok` value of `self`.
661
+ /// Calls `op` if the result is [ `Err`] , otherwise returns the [ `Ok`] value of `self`.
640
662
///
641
663
/// This function can be used for control flow based on result values.
642
664
///
665
+ /// [`Ok`]: enum.Result.html#variant.Ok
666
+ /// [`Err`]: enum.Result.html#variant.Err
667
+ ///
643
668
/// # Examples
644
669
///
645
670
/// Basic usage:
@@ -662,9 +687,12 @@ impl<T, E> Result<T, E> {
662
687
}
663
688
}
664
689
665
- /// Unwraps a result, yielding the content of an `Ok`.
690
+ /// Unwraps a result, yielding the content of an [ `Ok`] .
666
691
/// Else, it returns `optb`.
667
692
///
693
+ /// [`Ok`]: enum.Result.html#variant.Ok
694
+ /// [`Err`]: enum.Result.html#variant.Err
695
+ ///
668
696
/// # Examples
669
697
///
670
698
/// Basic usage:
@@ -686,8 +714,11 @@ impl<T, E> Result<T, E> {
686
714
}
687
715
}
688
716
689
- /// Unwraps a result, yielding the content of an `Ok`.
690
- /// If the value is an `Err` then it calls `op` with its value.
717
+ /// Unwraps a result, yielding the content of an [`Ok`].
718
+ /// If the value is an [`Err`] then it calls `op` with its value.
719
+ ///
720
+ /// [`Ok`]: enum.Result.html#variant.Ok
721
+ /// [`Err`]: enum.Result.html#variant.Err
691
722
///
692
723
/// # Examples
693
724
///
@@ -710,12 +741,15 @@ impl<T, E> Result<T, E> {
710
741
}
711
742
712
743
impl < T , E : fmt:: Debug > Result < T , E > {
713
- /// Unwraps a result, yielding the content of an `Ok`.
744
+ /// Unwraps a result, yielding the content of an [ `Ok`] .
714
745
///
715
746
/// # Panics
716
747
///
717
- /// Panics if the value is an `Err`, with a panic message provided by the
718
- /// `Err`'s value.
748
+ /// Panics if the value is an [`Err`], with a panic message provided by the
749
+ /// [`Err`]'s value.
750
+ ///
751
+ /// [`Ok`]: enum.Result.html#variant.Ok
752
+ /// [`Err`]: enum.Result.html#variant.Err
719
753
///
720
754
/// # Examples
721
755
///
@@ -739,12 +773,15 @@ impl<T, E: fmt::Debug> Result<T, E> {
739
773
}
740
774
}
741
775
742
- /// Unwraps a result, yielding the content of an `Ok`.
776
+ /// Unwraps a result, yielding the content of an [ `Ok`] .
743
777
///
744
778
/// # Panics
745
779
///
746
- /// Panics if the value is an `Err`, with a panic message including the
747
- /// passed message, and the content of the `Err`.
780
+ /// Panics if the value is an [`Err`], with a panic message including the
781
+ /// passed message, and the content of the [`Err`].
782
+ ///
783
+ /// [`Ok`]: enum.Result.html#variant.Ok
784
+ /// [`Err`]: enum.Result.html#variant.Err
748
785
///
749
786
/// # Examples
750
787
///
@@ -765,12 +802,16 @@ impl<T, E: fmt::Debug> Result<T, E> {
765
802
}
766
803
767
804
impl < T : fmt:: Debug , E > Result < T , E > {
768
- /// Unwraps a result, yielding the content of an `Err`.
805
+ /// Unwraps a result, yielding the content of an [ `Err`] .
769
806
///
770
807
/// # Panics
771
808
///
772
- /// Panics if the value is an `Ok`, with a custom panic message provided
773
- /// by the `Ok`'s value.
809
+ /// Panics if the value is an [`Ok`], with a custom panic message provided
810
+ /// by the [`Ok`]'s value.
811
+ ///
812
+ /// [`Ok`]: enum.Result.html#variant.Ok
813
+ /// [`Err`]: enum.Result.html#variant.Err
814
+ ///
774
815
///
775
816
/// # Examples
776
817
///
@@ -792,12 +833,15 @@ impl<T: fmt::Debug, E> Result<T, E> {
792
833
}
793
834
}
794
835
795
- /// Unwraps a result, yielding the content of an `Err`.
836
+ /// Unwraps a result, yielding the content of an [ `Err`] .
796
837
///
797
838
/// # Panics
798
839
///
799
- /// Panics if the value is an `Ok`, with a panic message including the
800
- /// passed message, and the content of the `Ok`.
840
+ /// Panics if the value is an [`Ok`], with a panic message including the
841
+ /// passed message, and the content of the [`Ok`].
842
+ ///
843
+ /// [`Ok`]: enum.Result.html#variant.Ok
844
+ /// [`Err`]: enum.Result.html#variant.Err
801
845
///
802
846
/// # Examples
803
847
///
@@ -820,16 +864,16 @@ impl<T: fmt::Debug, E> Result<T, E> {
820
864
impl < T : Default , E > Result < T , E > {
821
865
/// Returns the contained value or a default
822
866
///
823
- /// Consumes the `self` argument then, if `Ok`, returns the contained
824
- /// value, otherwise if `Err`, returns the default value for that
867
+ /// Consumes the `self` argument then, if [ `Ok`] , returns the contained
868
+ /// value, otherwise if [ `Err`] , returns the default value for that
825
869
/// type.
826
870
///
827
871
/// # Examples
828
872
///
829
873
/// Convert a string to an integer, turning poorly-formed strings
830
874
/// into 0 (the default value for integers). [`parse`] converts
831
875
/// a string to any other type that implements [`FromStr`], returning an
832
- /// `Err` on error.
876
+ /// [ `Err`] on error.
833
877
///
834
878
/// ```
835
879
/// let good_year_from_input = "1909";
@@ -843,6 +887,8 @@ impl<T: Default, E> Result<T, E> {
843
887
///
844
888
/// [`parse`]: ../../std/primitive.str.html#method.parse
845
889
/// [`FromStr`]: ../../std/str/trait.FromStr.html
890
+ /// [`Ok`]: enum.Result.html#variant.Ok
891
+ /// [`Err`]: enum.Result.html#variant.Err
846
892
#[ inline]
847
893
#[ stable( feature = "result_unwrap_or_default" , since = "1.16.0" ) ]
848
894
pub fn unwrap_or_default ( self ) -> T {
0 commit comments