60
60
//! the optional owned box, `Option<Box<T>>`.
61
61
//!
62
62
//! The following example uses `Option` to create an optional box of
63
- //! `int `. Notice that in order to use the inner `int ` value first the
63
+ //! `i32 `. Notice that in order to use the inner `i32 ` value first the
64
64
//! `check_optional` function needs to use pattern matching to
65
65
//! determine whether the box has a value (i.e. it is `Some(...)`) or
66
66
//! not (`None`).
67
67
//!
68
68
//! ```
69
- //! let optional: Option<Box<int >> = None;
69
+ //! let optional: Option<Box<i32 >> = None;
70
70
//! check_optional(&optional);
71
71
//!
72
- //! let optional: Option<Box<int >> = Some(Box::new(9000));
72
+ //! let optional: Option<Box<i32 >> = Some(Box::new(9000));
73
73
//! check_optional(&optional);
74
74
//!
75
- //! fn check_optional(optional: &Option<Box<int >>) {
75
+ //! fn check_optional(optional: &Option<Box<i32 >>) {
76
76
//! match *optional {
77
77
//! Some(ref p) => println!("have value {}", p),
78
78
//! None => println!("have no value")
108
108
//! Initialize a result to `None` before a loop:
109
109
//!
110
110
//! ```
111
- //! enum Kingdom { Plant(uint , &'static str), Animal(uint , &'static str) }
111
+ //! enum Kingdom { Plant(u32 , &'static str), Animal(u32 , &'static str) }
112
112
//!
113
113
//! // A list of data to search through.
114
114
//! let all_the_big_things = [
@@ -188,10 +188,10 @@ impl<T> Option<T> {
188
188
/// # Example
189
189
///
190
190
/// ```
191
- /// let x: Option<uint > = Some(2);
191
+ /// let x: Option<u32 > = Some(2);
192
192
/// assert_eq!(x.is_some(), true);
193
193
///
194
- /// let x: Option<uint > = None;
194
+ /// let x: Option<u32 > = None;
195
195
/// assert_eq!(x.is_some(), false);
196
196
/// ```
197
197
#[ inline]
@@ -208,10 +208,10 @@ impl<T> Option<T> {
208
208
/// # Example
209
209
///
210
210
/// ```
211
- /// let x: Option<uint > = Some(2);
211
+ /// let x: Option<u32 > = Some(2);
212
212
/// assert_eq!(x.is_none(), false);
213
213
///
214
- /// let x: Option<uint > = None;
214
+ /// let x: Option<u32 > = None;
215
215
/// assert_eq!(x.is_none(), true);
216
216
/// ```
217
217
#[ inline]
@@ -228,7 +228,7 @@ impl<T> Option<T> {
228
228
///
229
229
/// # Example
230
230
///
231
- /// Convert an `Option<String>` into an `Option<int >`, preserving the original.
231
+ /// Convert an `Option<String>` into an `Option<usize >`, preserving the original.
232
232
/// The `map` method takes the `self` argument by value, consuming the original,
233
233
/// so this technique uses `as_ref` to first take an `Option` to a reference
234
234
/// to the value inside the original.
@@ -237,7 +237,7 @@ impl<T> Option<T> {
237
237
/// let num_as_str: Option<String> = Some("10".to_string());
238
238
/// // First, cast `Option<String>` to `Option<&String>` with `as_ref`,
239
239
/// // then consume *that* with `map`, leaving `num_as_str` on the stack.
240
- /// let num_as_int: Option<uint > = num_as_str.as_ref().map(|n| n.len());
240
+ /// let num_as_int: Option<usize > = num_as_str.as_ref().map(|n| n.len());
241
241
/// println!("still can print num_as_str: {:?}", num_as_str);
242
242
/// ```
243
243
#[ inline]
@@ -406,12 +406,12 @@ impl<T> Option<T> {
406
406
///
407
407
/// # Example
408
408
///
409
- /// Convert an `Option<String>` into an `Option<uint >`, consuming the original:
409
+ /// Convert an `Option<String>` into an `Option<usize >`, consuming the original:
410
410
///
411
411
/// ```
412
412
/// let num_as_str: Option<String> = Some("10".to_string());
413
413
/// // `Option::map` takes self *by value*, consuming `num_as_str`
414
- /// let num_as_int: Option<uint > = num_as_str.map(|n| n.len());
414
+ /// let num_as_int: Option<usize > = num_as_str.map(|n| n.len());
415
415
/// ```
416
416
#[ inline]
417
417
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -518,7 +518,7 @@ impl<T> Option<T> {
518
518
/// let x = Some(4);
519
519
/// assert_eq!(x.iter().next(), Some(&4));
520
520
///
521
- /// let x: Option<uint > = None;
521
+ /// let x: Option<u32 > = None;
522
522
/// assert_eq!(x.iter().next(), None);
523
523
/// ```
524
524
#[ inline]
@@ -539,7 +539,7 @@ impl<T> Option<T> {
539
539
/// }
540
540
/// assert_eq!(x, Some(42));
541
541
///
542
- /// let mut x: Option<uint > = None;
542
+ /// let mut x: Option<u32 > = None;
543
543
/// assert_eq!(x.iter_mut().next(), None);
544
544
/// ```
545
545
#[ inline]
@@ -581,15 +581,15 @@ impl<T> Option<T> {
581
581
/// let y: Option<&str> = None;
582
582
/// assert_eq!(x.and(y), None);
583
583
///
584
- /// let x: Option<uint > = None;
584
+ /// let x: Option<u32 > = None;
585
585
/// let y = Some("foo");
586
586
/// assert_eq!(x.and(y), None);
587
587
///
588
588
/// let x = Some(2);
589
589
/// let y = Some("foo");
590
590
/// assert_eq!(x.and(y), Some("foo"));
591
591
///
592
- /// let x: Option<uint > = None;
592
+ /// let x: Option<u32 > = None;
593
593
/// let y: Option<&str> = None;
594
594
/// assert_eq!(x.and(y), None);
595
595
/// ```
@@ -608,8 +608,8 @@ impl<T> Option<T> {
608
608
/// # Example
609
609
///
610
610
/// ```
611
- /// fn sq(x: uint ) -> Option<uint > { Some(x * x) }
612
- /// fn nope(_: uint ) -> Option<uint > { None }
611
+ /// fn sq(x: u32 ) -> Option<u32 > { Some(x * x) }
612
+ /// fn nope(_: u32 ) -> Option<u32 > { None }
613
613
///
614
614
/// assert_eq!(Some(2).and_then(sq).and_then(sq), Some(16));
615
615
/// assert_eq!(Some(2).and_then(sq).and_then(nope), None);
@@ -642,7 +642,7 @@ impl<T> Option<T> {
642
642
/// let y = Some(100);
643
643
/// assert_eq!(x.or(y), Some(2));
644
644
///
645
- /// let x: Option<uint > = None;
645
+ /// let x: Option<u32 > = None;
646
646
/// let y = None;
647
647
/// assert_eq!(x.or(y), None);
648
648
/// ```
@@ -690,7 +690,7 @@ impl<T> Option<T> {
690
690
/// x.take();
691
691
/// assert_eq!(x, None);
692
692
///
693
- /// let mut x: Option<uint > = None;
693
+ /// let mut x: Option<u32 > = None;
694
694
/// x.take();
695
695
/// assert_eq!(x, None);
696
696
/// ```
@@ -789,7 +789,7 @@ impl<A> Iterator for Item<A> {
789
789
}
790
790
791
791
#[ inline]
792
- fn size_hint ( & self ) -> ( uint , Option < uint > ) {
792
+ fn size_hint ( & self ) -> ( usize , Option < usize > ) {
793
793
match self . opt {
794
794
Some ( _) => ( 1 , Some ( 1 ) ) ,
795
795
None => ( 0 , Some ( 0 ) ) ,
@@ -817,7 +817,7 @@ impl<'a, A> Iterator for Iter<'a, A> {
817
817
#[ inline]
818
818
fn next ( & mut self ) -> Option < & ' a A > { self . inner . next ( ) }
819
819
#[ inline]
820
- fn size_hint ( & self ) -> ( uint , Option < uint > ) { self . inner . size_hint ( ) }
820
+ fn size_hint ( & self ) -> ( usize , Option < usize > ) { self . inner . size_hint ( ) }
821
821
}
822
822
823
823
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -847,7 +847,7 @@ impl<'a, A> Iterator for IterMut<'a, A> {
847
847
#[ inline]
848
848
fn next ( & mut self ) -> Option < & ' a mut A > { self . inner . next ( ) }
849
849
#[ inline]
850
- fn size_hint ( & self ) -> ( uint , Option < uint > ) { self . inner . size_hint ( ) }
850
+ fn size_hint ( & self ) -> ( usize , Option < usize > ) { self . inner . size_hint ( ) }
851
851
}
852
852
853
853
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -870,7 +870,7 @@ impl<A> Iterator for IntoIter<A> {
870
870
#[ inline]
871
871
fn next ( & mut self ) -> Option < A > { self . inner . next ( ) }
872
872
#[ inline]
873
- fn size_hint ( & self ) -> ( uint , Option < uint > ) { self . inner . size_hint ( ) }
873
+ fn size_hint ( & self ) -> ( usize , Option < usize > ) { self . inner . size_hint ( ) }
874
874
}
875
875
876
876
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -896,11 +896,11 @@ impl<A, V: FromIterator<A>> FromIterator<Option<A>> for Option<V> {
896
896
/// checking for overflow:
897
897
///
898
898
/// ```rust
899
- /// use std::uint ;
899
+ /// use std::u16 ;
900
900
///
901
901
/// let v = vec!(1, 2);
902
- /// let res: Option<Vec<uint >> = v.iter().map(|&x: &uint |
903
- /// if x == uint ::MAX { None }
902
+ /// let res: Option<Vec<u16 >> = v.iter().map(|&x: &u16 |
903
+ /// if x == u16 ::MAX { None }
904
904
/// else { Some(x + 1) }
905
905
/// ).collect();
906
906
/// assert!(res == Some(vec!(2, 3)));
0 commit comments