doc: unwrap is discouraged, so use Some
This commit is contained in:
parent
750f2c63f2
commit
683da9c384
@ -137,7 +137,7 @@ fn count(self) -> usize where Self: Sized {
|
||||
///
|
||||
/// ```
|
||||
/// let a = [1, 2, 3, 4, 5];
|
||||
/// assert_eq!(a.iter().last().unwrap(), &5);
|
||||
/// assert_eq!(a.iter().last(), Some(&5));
|
||||
/// ```
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@ -155,7 +155,7 @@ fn last(self) -> Option<Self::Item> where Self: Sized {
|
||||
/// ```
|
||||
/// let a = [1, 2, 3, 4, 5];
|
||||
/// let mut it = a.iter();
|
||||
/// assert_eq!(it.nth(2).unwrap(), &3);
|
||||
/// assert_eq!(it.nth(2), Some(&3));
|
||||
/// assert_eq!(it.nth(2), None);
|
||||
/// ```
|
||||
#[inline]
|
||||
@ -178,8 +178,8 @@ fn nth(&mut self, mut n: usize) -> Option<Self::Item> where Self: Sized {
|
||||
/// let a = [0];
|
||||
/// let b = [1];
|
||||
/// let mut it = a.iter().chain(b.iter());
|
||||
/// assert_eq!(it.next().unwrap(), &0);
|
||||
/// assert_eq!(it.next().unwrap(), &1);
|
||||
/// assert_eq!(it.next(), Some(&0));
|
||||
/// assert_eq!(it.next(), Some(&1));
|
||||
/// assert!(it.next().is_none());
|
||||
/// ```
|
||||
#[inline]
|
||||
@ -201,7 +201,7 @@ fn chain<U>(self, other: U) -> Chain<Self, U::IntoIter> where
|
||||
/// let a = [0];
|
||||
/// let b = [1];
|
||||
/// let mut it = a.iter().zip(b.iter());
|
||||
/// assert_eq!(it.next().unwrap(), (&0, &1));
|
||||
/// assert_eq!(it.next(), Some((&0, &1)));
|
||||
/// assert!(it.next().is_none());
|
||||
/// ```
|
||||
///
|
||||
@ -234,8 +234,8 @@ fn zip<U>(self, other: U) -> Zip<Self, U::IntoIter> where
|
||||
/// ```
|
||||
/// let a = [1, 2];
|
||||
/// let mut it = a.iter().map(|&x| 2 * x);
|
||||
/// assert_eq!(it.next().unwrap(), 2);
|
||||
/// assert_eq!(it.next().unwrap(), 4);
|
||||
/// assert_eq!(it.next(), Some(2));
|
||||
/// assert_eq!(it.next(), Some(4));
|
||||
/// assert!(it.next().is_none());
|
||||
/// ```
|
||||
#[inline]
|
||||
@ -255,7 +255,7 @@ fn map<B, F>(self, f: F) -> Map<Self, F> where
|
||||
/// ```
|
||||
/// let a = [1, 2];
|
||||
/// let mut it = a.iter().filter(|&x| *x > 1);
|
||||
/// assert_eq!(it.next().unwrap(), &2);
|
||||
/// assert_eq!(it.next(), Some(&2));
|
||||
/// assert!(it.next().is_none());
|
||||
/// ```
|
||||
#[inline]
|
||||
@ -275,7 +275,7 @@ fn filter<P>(self, predicate: P) -> Filter<Self, P> where
|
||||
/// ```
|
||||
/// let a = [1, 2];
|
||||
/// let mut it = a.iter().filter_map(|&x| if x > 1 {Some(2 * x)} else {None});
|
||||
/// assert_eq!(it.next().unwrap(), 4);
|
||||
/// assert_eq!(it.next(), Some(4));
|
||||
/// assert!(it.next().is_none());
|
||||
/// ```
|
||||
#[inline]
|
||||
@ -310,8 +310,8 @@ fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F> where
|
||||
/// ```
|
||||
/// let a = [100, 200];
|
||||
/// let mut it = a.iter().enumerate();
|
||||
/// assert_eq!(it.next().unwrap(), (0, &100));
|
||||
/// assert_eq!(it.next().unwrap(), (1, &200));
|
||||
/// assert_eq!(it.next(), Some((0, &100)));
|
||||
/// assert_eq!(it.next(), Some((1, &200)));
|
||||
/// assert!(it.next().is_none());
|
||||
/// ```
|
||||
#[inline]
|
||||
@ -353,9 +353,9 @@ fn peekable(self) -> Peekable<Self> where Self: Sized {
|
||||
/// ```
|
||||
/// let a = [1, 2, 3, 4, 5];
|
||||
/// let mut it = a.iter().skip_while(|&a| *a < 3);
|
||||
/// assert_eq!(it.next().unwrap(), &3);
|
||||
/// assert_eq!(it.next().unwrap(), &4);
|
||||
/// assert_eq!(it.next().unwrap(), &5);
|
||||
/// assert_eq!(it.next(), Some(&3));
|
||||
/// assert_eq!(it.next(), Some(&4));
|
||||
/// assert_eq!(it.next(), Some(&5));
|
||||
/// assert!(it.next().is_none());
|
||||
/// ```
|
||||
#[inline]
|
||||
@ -375,8 +375,8 @@ fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P> where
|
||||
/// ```
|
||||
/// let a = [1, 2, 3, 4, 5];
|
||||
/// let mut it = a.iter().take_while(|&a| *a < 3);
|
||||
/// assert_eq!(it.next().unwrap(), &1);
|
||||
/// assert_eq!(it.next().unwrap(), &2);
|
||||
/// assert_eq!(it.next(), Some(&1));
|
||||
/// assert_eq!(it.next(), Some(&2));
|
||||
/// assert!(it.next().is_none());
|
||||
/// ```
|
||||
#[inline]
|
||||
@ -395,8 +395,8 @@ fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P> where
|
||||
/// ```
|
||||
/// let a = [1, 2, 3, 4, 5];
|
||||
/// let mut it = a.iter().skip(3);
|
||||
/// assert_eq!(it.next().unwrap(), &4);
|
||||
/// assert_eq!(it.next().unwrap(), &5);
|
||||
/// assert_eq!(it.next(), Some(&4));
|
||||
/// assert_eq!(it.next(), Some(&5));
|
||||
/// assert!(it.next().is_none());
|
||||
/// ```
|
||||
#[inline]
|
||||
@ -413,9 +413,9 @@ fn skip(self, n: usize) -> Skip<Self> where Self: Sized {
|
||||
/// ```
|
||||
/// let a = [1, 2, 3, 4, 5];
|
||||
/// let mut it = a.iter().take(3);
|
||||
/// assert_eq!(it.next().unwrap(), &1);
|
||||
/// assert_eq!(it.next().unwrap(), &2);
|
||||
/// assert_eq!(it.next().unwrap(), &3);
|
||||
/// assert_eq!(it.next(), Some(&1));
|
||||
/// assert_eq!(it.next(), Some(&2));
|
||||
/// assert_eq!(it.next(), Some(&3));
|
||||
/// assert!(it.next().is_none());
|
||||
/// ```
|
||||
#[inline]
|
||||
@ -437,11 +437,11 @@ fn take(self, n: usize) -> Take<Self> where Self: Sized, {
|
||||
/// *fac = *fac * x;
|
||||
/// Some(*fac)
|
||||
/// });
|
||||
/// assert_eq!(it.next().unwrap(), 1);
|
||||
/// assert_eq!(it.next().unwrap(), 2);
|
||||
/// assert_eq!(it.next().unwrap(), 6);
|
||||
/// assert_eq!(it.next().unwrap(), 24);
|
||||
/// assert_eq!(it.next().unwrap(), 120);
|
||||
/// assert_eq!(it.next(), Some(1));
|
||||
/// assert_eq!(it.next(), Some(2));
|
||||
/// assert_eq!(it.next(), Some(6));
|
||||
/// assert_eq!(it.next(), Some(24));
|
||||
/// assert_eq!(it.next(), Some(120));
|
||||
/// assert!(it.next().is_none());
|
||||
/// ```
|
||||
#[inline]
|
||||
@ -680,7 +680,7 @@ fn any<F>(&mut self, mut f: F) -> bool where
|
||||
/// ```
|
||||
/// let a = [1, 2, 3, 4, 5];
|
||||
/// let mut it = a.iter();
|
||||
/// assert_eq!(it.find(|&x| *x == 3).unwrap(), &3);
|
||||
/// assert_eq!(it.find(|&x| *x == 3), Some(&3));
|
||||
/// assert_eq!(it.collect::<Vec<_>>(), [&4, &5]);
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@ -715,7 +715,7 @@ fn find<P>(&mut self, mut predicate: P) -> Option<Self::Item> where
|
||||
/// ```
|
||||
/// let a = [1, 2, 3, 4, 5];
|
||||
/// let mut it = a.iter();
|
||||
/// assert_eq!(it.position(|x| *x == 3).unwrap(), 2);
|
||||
/// assert_eq!(it.position(|x| *x == 3), Some(2));
|
||||
/// assert_eq!(it.collect::<Vec<_>>(), [&4, &5]);
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@ -743,7 +743,7 @@ fn position<P>(&mut self, mut predicate: P) -> Option<usize> where
|
||||
/// ```
|
||||
/// let a = [1, 2, 2, 4, 5];
|
||||
/// let mut it = a.iter();
|
||||
/// assert_eq!(it.rposition(|x| *x == 2).unwrap(), 2);
|
||||
/// assert_eq!(it.rposition(|x| *x == 2), Some(2));
|
||||
/// assert_eq!(it.collect::<Vec<_>>(), [&1, &2]);
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@ -773,7 +773,7 @@ fn rposition<P>(&mut self, mut predicate: P) -> Option<usize> where
|
||||
///
|
||||
/// ```
|
||||
/// let a = [1, 2, 3, 4, 5];
|
||||
/// assert_eq!(a.iter().max().unwrap(), &5);
|
||||
/// assert_eq!(a.iter().max(), Some(&5));
|
||||
/// ```
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@ -796,7 +796,7 @@ fn max(self) -> Option<Self::Item> where Self: Sized, Self::Item: Ord
|
||||
///
|
||||
/// ```
|
||||
/// let a = [1, 2, 3, 4, 5];
|
||||
/// assert_eq!(a.iter().min().unwrap(), &1);
|
||||
/// assert_eq!(a.iter().min(), Some(&1));
|
||||
/// ```
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@ -1025,9 +1025,9 @@ fn cloned<'a, T: 'a>(self) -> Cloned<Self>
|
||||
/// ```
|
||||
/// let a = [1, 2];
|
||||
/// let mut it = a.iter().cycle();
|
||||
/// assert_eq!(it.next().unwrap(), &1);
|
||||
/// assert_eq!(it.next().unwrap(), &2);
|
||||
/// assert_eq!(it.next().unwrap(), &1);
|
||||
/// assert_eq!(it.next(), Some(&1));
|
||||
/// assert_eq!(it.next(), Some(&2));
|
||||
/// assert_eq!(it.next(), Some(&1));
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
|
Loading…
Reference in New Issue
Block a user