@@ -174,7 +174,7 @@ impl<T> Option<T> {
174
174
// Querying the contained values
175
175
/////////////////////////////////////////////////////////////////////////
176
176
177
- /// Returns `true` if the option is a `Some` value.
177
+ /// Returns `true` if the option is a [ `Some`] value.
178
178
///
179
179
/// # Examples
180
180
///
@@ -185,6 +185,8 @@ impl<T> Option<T> {
185
185
/// let x: Option<u32> = None;
186
186
/// assert_eq!(x.is_some(), false);
187
187
/// ```
188
+ ///
189
+ /// [`Some`]: #variant.Some
188
190
#[ inline]
189
191
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
190
192
pub fn is_some ( & self ) -> bool {
@@ -194,7 +196,7 @@ impl<T> Option<T> {
194
196
}
195
197
}
196
198
197
- /// Returns `true` if the option is a `None` value.
199
+ /// Returns `true` if the option is a [ `None`] value.
198
200
///
199
201
/// # Examples
200
202
///
@@ -205,6 +207,8 @@ impl<T> Option<T> {
205
207
/// let x: Option<u32> = None;
206
208
/// assert_eq!(x.is_none(), true);
207
209
/// ```
210
+ ///
211
+ /// [`None`]: #variant.None
208
212
#[ inline]
209
213
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
210
214
pub fn is_none ( & self ) -> bool {
@@ -269,13 +273,14 @@ impl<T> Option<T> {
269
273
// Getting to contained values
270
274
/////////////////////////////////////////////////////////////////////////
271
275
272
- /// Unwraps an option, yielding the content of a `Some`.
276
+ /// Unwraps an option, yielding the content of a [ `Some`] .
273
277
///
274
278
/// # Panics
275
279
///
276
280
/// Panics if the value is a [`None`] with a custom panic message provided by
277
281
/// `msg`.
278
282
///
283
+ /// [`Some`]: #variant.Some
279
284
/// [`None`]: #variant.None
280
285
///
281
286
/// # Examples
@@ -298,16 +303,17 @@ impl<T> Option<T> {
298
303
}
299
304
}
300
305
301
- /// Moves the value `v` out of the `Option<T>` if it is `Some(v)`.
306
+ /// Moves the value `v` out of the `Option<T>` if it is [ `Some(v)`] .
302
307
///
303
308
/// In general, because this function may panic, its use is discouraged.
304
- /// Instead, prefer to use pattern matching and handle the `None`
309
+ /// Instead, prefer to use pattern matching and handle the [ `None`]
305
310
/// case explicitly.
306
311
///
307
312
/// # Panics
308
313
///
309
314
/// Panics if the self value equals [`None`].
310
315
///
316
+ /// [`Some(v)`]: #variant.Some
311
317
/// [`None`]: #variant.None
312
318
///
313
319
/// # Examples
@@ -395,7 +401,9 @@ impl<T> Option<T> {
395
401
}
396
402
397
403
/// Applies a function to the contained value (if any),
398
- /// or returns a `default` (if not).
404
+ /// or returns a [`default`][] (if not).
405
+ ///
406
+ /// [`default`]: ../default/trait.Default.html#tymethod.default
399
407
///
400
408
/// # Examples
401
409
///
@@ -416,7 +424,9 @@ impl<T> Option<T> {
416
424
}
417
425
418
426
/// Applies a function to the contained value (if any),
419
- /// or computes a `default` (if not).
427
+ /// or computes a [`default`][] (if not).
428
+ ///
429
+ /// [`default`]: ../default/trait.Default.html#tymethod.default
420
430
///
421
431
/// # Examples
422
432
///
@@ -438,12 +448,14 @@ impl<T> Option<T> {
438
448
}
439
449
}
440
450
441
- /// Transforms the `Option<T>` into a [`Result<T, E>`], mapping `Some(v)` to
442
- /// [`Ok(v)`] and `None` to [`Err(err)`][Err ].
451
+ /// Transforms the `Option<T>` into a [`Result<T, E>`], mapping [ `Some(v)`] to
452
+ /// [`Ok(v)`] and [ `None`] to [`Err(err)`].
443
453
///
444
454
/// [`Result<T, E>`]: ../../std/result/enum.Result.html
445
455
/// [`Ok(v)`]: ../../std/result/enum.Result.html#variant.Ok
446
- /// [Err]: ../../std/result/enum.Result.html#variant.Err
456
+ /// [`Err(err)`]: ../../std/result/enum.Result.html#variant.Err
457
+ /// [`None`]: #variant.None
458
+ /// [`Some(v)`]: #variant.Some
447
459
///
448
460
/// # Examples
449
461
///
@@ -463,12 +475,14 @@ impl<T> Option<T> {
463
475
}
464
476
}
465
477
466
- /// Transforms the `Option<T>` into a [`Result<T, E>`], mapping `Some(v)` to
467
- /// [`Ok(v)`] and `None` to [`Err(err())`][Err ].
478
+ /// Transforms the `Option<T>` into a [`Result<T, E>`], mapping [ `Some(v)`] to
479
+ /// [`Ok(v)`] and [ `None`] to [`Err(err())`].
468
480
///
469
481
/// [`Result<T, E>`]: ../../std/result/enum.Result.html
470
482
/// [`Ok(v)`]: ../../std/result/enum.Result.html#variant.Ok
471
- /// [Err]: ../../std/result/enum.Result.html#variant.Err
483
+ /// [`Err(err())`]: ../../std/result/enum.Result.html#variant.Err
484
+ /// [`None`]: #variant.None
485
+ /// [`Some(v)`]: #variant.Some
472
486
///
473
487
/// # Examples
474
488
///
@@ -534,7 +548,9 @@ impl<T> Option<T> {
534
548
// Boolean operations on the values, eager and lazy
535
549
/////////////////////////////////////////////////////////////////////////
536
550
537
- /// Returns `None` if the option is `None`, otherwise returns `optb`.
551
+ /// Returns [`None`] if the option is [`None`], otherwise returns `optb`.
552
+ ///
553
+ /// [`None`]: #variant.None
538
554
///
539
555
/// # Examples
540
556
///
@@ -564,11 +580,13 @@ impl<T> Option<T> {
564
580
}
565
581
}
566
582
567
- /// Returns `None` if the option is `None`, otherwise calls `f` with the
583
+ /// Returns [ `None`] if the option is [ `None`] , otherwise calls `f` with the
568
584
/// wrapped value and returns the result.
569
585
///
570
586
/// Some languages call this operation flatmap.
571
587
///
588
+ /// [`None`]: #variant.None
589
+ ///
572
590
/// # Examples
573
591
///
574
592
/// ```
@@ -645,9 +663,11 @@ impl<T> Option<T> {
645
663
// Entry-like operations to insert if None and return a reference
646
664
/////////////////////////////////////////////////////////////////////////
647
665
648
- /// Inserts `v` into the option if it is `None`, then
666
+ /// Inserts `v` into the option if it is [ `None`] , then
649
667
/// returns a mutable reference to the contained value.
650
668
///
669
+ /// [`None`]: #variant.None
670
+ ///
651
671
/// # Examples
652
672
///
653
673
/// ```
@@ -678,9 +698,11 @@ impl<T> Option<T> {
678
698
}
679
699
}
680
700
681
- /// Inserts a value computed from `f` into the option if it is `None`, then
701
+ /// Inserts a value computed from `f` into the option if it is [ `None`] , then
682
702
/// returns a mutable reference to the contained value.
683
703
///
704
+ /// [`None`]: #variant.None
705
+ ///
684
706
/// # Examples
685
707
///
686
708
/// ```
@@ -715,7 +737,9 @@ impl<T> Option<T> {
715
737
// Misc
716
738
/////////////////////////////////////////////////////////////////////////
717
739
718
- /// Takes the value out of the option, leaving a `None` in its place.
740
+ /// Takes the value out of the option, leaving a [`None`] in its place.
741
+ ///
742
+ /// [`None`]: #variant.None
719
743
///
720
744
/// # Examples
721
745
///
@@ -757,16 +781,16 @@ impl<'a, T: Clone> Option<&'a T> {
757
781
impl < T : Default > Option < T > {
758
782
/// Returns the contained value or a default
759
783
///
760
- /// Consumes the `self` argument then, if `Some`, returns the contained
761
- /// value, otherwise if `None`, returns the default value for that
784
+ /// Consumes the `self` argument then, if [ `Some`] , returns the contained
785
+ /// value, otherwise if [ `None`] , returns the default value for that
762
786
/// type.
763
787
///
764
788
/// # Examples
765
789
///
766
790
/// Convert a string to an integer, turning poorly-formed strings
767
- /// into 0 (the default value for integers). `parse` converts
768
- /// a string to any other type that implements `FromStr`, returning
769
- /// `None` on error.
791
+ /// into 0 (the default value for integers). [ `parse`] converts
792
+ /// a string to any other type that implements [ `FromStr`] , returning
793
+ /// [ `None`] on error.
770
794
///
771
795
/// ```
772
796
/// let good_year_from_input = "1909";
@@ -777,6 +801,11 @@ impl<T: Default> Option<T> {
777
801
/// assert_eq!(1909, good_year);
778
802
/// assert_eq!(0, bad_year);
779
803
/// ```
804
+ ///
805
+ /// [`Some`]: #variant.Some
806
+ /// [`None`]: #variant.None
807
+ /// [`parse`]: ../../std/primitive.str.html#method.parse
808
+ /// [`FromStr`]: ../../std/str/trait.FromStr.html
780
809
#[ inline]
781
810
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
782
811
pub fn unwrap_or_default ( self ) -> T {
@@ -801,7 +830,9 @@ fn expect_failed(msg: &str) -> ! {
801
830
802
831
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
803
832
impl < T > Default for Option < T > {
804
- /// Returns None.
833
+ /// Returns [`None`].
834
+ ///
835
+ /// [`None`]: #variant.None
805
836
#[ inline]
806
837
fn default ( ) -> Option < T > { None }
807
838
}
@@ -1020,8 +1051,8 @@ unsafe impl<A> TrustedLen for IntoIter<A> {}
1020
1051
1021
1052
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1022
1053
impl < A , V : FromIterator < A > > FromIterator < Option < A > > for Option < V > {
1023
- /// Takes each element in the `Iterator`: if it is `None`, no further
1024
- /// elements are taken, and the `None` is returned. Should no `None` occur, a
1054
+ /// Takes each element in the [ `Iterator`] : if it is [ `None`] , no further
1055
+ /// elements are taken, and the [ `None`] is returned. Should no [ `None`] occur, a
1025
1056
/// container with the values of each `Option` is returned.
1026
1057
///
1027
1058
/// Here is an example which increments every integer in a vector,
@@ -1037,6 +1068,9 @@ impl<A, V: FromIterator<A>> FromIterator<Option<A>> for Option<V> {
1037
1068
/// ).collect();
1038
1069
/// assert!(res == Some(vec![2, 3]));
1039
1070
/// ```
1071
+ ///
1072
+ /// [`Iterator`]: ../iter/trait.Iterator.html
1073
+ /// [`None`]: enum.Option.html#variant.None
1040
1074
#[ inline]
1041
1075
fn from_iter < I : IntoIterator < Item =Option < A > > > ( iter : I ) -> Option < V > {
1042
1076
// FIXME(#11084): This could be replaced with Iterator::scan when this
0 commit comments