Skip to content

Commit 16d4b7b

Browse files
committed
doc: Explain meaning of Result iters and link to factory functions.
1 parent 7f78b42 commit 16d4b7b

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

src/libcore/result.rs

+26-3
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,8 @@ impl<T, E> Result<T, E> {
501501

502502
/// Returns an iterator over the possibly contained value.
503503
///
504+
/// The iterator yields one value if the result is [`Ok`], otherwise none.
505+
///
504506
/// # Examples
505507
///
506508
/// Basic usage:
@@ -512,6 +514,8 @@ impl<T, E> Result<T, E> {
512514
/// let x: Result<u32, &str> = Err("nothing!");
513515
/// assert_eq!(x.iter().next(), None);
514516
/// ```
517+
///
518+
/// [`Ok`]: enum.Result.html#variant.Ok
515519
#[inline]
516520
#[stable(feature = "rust1", since = "1.0.0")]
517521
pub fn iter(&self) -> Iter<T> {
@@ -520,6 +524,8 @@ impl<T, E> Result<T, E> {
520524

521525
/// Returns a mutable iterator over the possibly contained value.
522526
///
527+
/// The iterator yields one value if the result is [`Ok`], otherwise none.
528+
///
523529
/// # Examples
524530
///
525531
/// Basic usage:
@@ -535,6 +541,8 @@ impl<T, E> Result<T, E> {
535541
/// let mut x: Result<u32, &str> = Err("nothing!");
536542
/// assert_eq!(x.iter_mut().next(), None);
537543
/// ```
544+
///
545+
/// [`Ok`]: enum.Result.html#variant.Ok
538546
#[inline]
539547
#[stable(feature = "rust1", since = "1.0.0")]
540548
pub fn iter_mut(&mut self) -> IterMut<T> {
@@ -848,6 +856,8 @@ impl<T, E> IntoIterator for Result<T, E> {
848856

849857
/// Returns a consuming iterator over the possibly contained value.
850858
///
859+
/// The iterator yields one value if the result is [`Ok`], otherwise none.
860+
///
851861
/// # Examples
852862
///
853863
/// Basic usage:
@@ -861,6 +871,8 @@ impl<T, E> IntoIterator for Result<T, E> {
861871
/// let v: Vec<u32> = x.into_iter().collect();
862872
/// assert_eq!(v, []);
863873
/// ```
874+
///
875+
/// [`Ok`]: enum.Result.html#variant.Ok
864876
#[inline]
865877
fn into_iter(self) -> IntoIter<T> {
866878
IntoIter { inner: self.ok() }
@@ -893,8 +905,13 @@ impl<'a, T, E> IntoIterator for &'a mut Result<T, E> {
893905

894906
/// An iterator over a reference to the [`Ok`] variant of a [`Result`].
895907
///
908+
/// The iterator yields one value if the result is [`Ok`], otherwise none.
909+
///
910+
/// Created by [`Result::iter`].
911+
///
896912
/// [`Ok`]: enum.Result.html#variant.Ok
897913
/// [`Result`]: enum.Result.html
914+
/// [`Result::iter`]: enum.Result.html#method.iter
898915
#[derive(Debug)]
899916
#[stable(feature = "rust1", since = "1.0.0")]
900917
pub struct Iter<'a, T: 'a> { inner: Option<&'a T> }
@@ -934,8 +951,11 @@ impl<'a, T> Clone for Iter<'a, T> {
934951

935952
/// An iterator over a mutable reference to the [`Ok`] variant of a [`Result`].
936953
///
954+
/// Created by [`Result::iter_mut`].
955+
///
937956
/// [`Ok`]: enum.Result.html#variant.Ok
938957
/// [`Result`]: enum.Result.html
958+
/// [`Result::iter_mut`]: enum.Result.html#method.iter_mut
939959
#[derive(Debug)]
940960
#[stable(feature = "rust1", since = "1.0.0")]
941961
pub struct IterMut<'a, T: 'a> { inner: Option<&'a mut T> }
@@ -968,9 +988,12 @@ impl<'a, T> FusedIterator for IterMut<'a, T> {}
968988
#[unstable(feature = "trusted_len", issue = "37572")]
969989
unsafe impl<'a, A> TrustedLen for IterMut<'a, A> {}
970990

971-
/// An iterator over the value in a [`Ok`] variant of a [`Result`]. This struct is
972-
/// created by the [`into_iter`] method on [`Result`][`Result`] (provided by
973-
/// the [`IntoIterator`] trait).
991+
/// An iterator over the value in a [`Ok`] variant of a [`Result`].
992+
///
993+
/// The iterator yields one value if the result is [`Ok`], otherwise none.
994+
///
995+
/// This struct is created by the [`into_iter`] method on
996+
/// [`Result`][`Result`] (provided by the [`IntoIterator`] trait).
974997
///
975998
/// [`Ok`]: enum.Result.html#variant.Ok
976999
/// [`Result`]: enum.Result.html

0 commit comments

Comments
 (0)