more int and cloned cleanup in collections
This commit is contained in:
parent
cca1cf613b
commit
1e75a05a0e
@ -255,7 +255,7 @@ impl<T: Ord> BinaryHeap<T> {
|
||||
///
|
||||
/// // Print 1, 2, 3, 4 in arbitrary order
|
||||
/// for x in heap.into_iter() {
|
||||
/// // x has type int, not &int
|
||||
/// // x has type i32, not &i32
|
||||
/// println!("{}", x);
|
||||
/// }
|
||||
/// ```
|
||||
|
@ -1783,7 +1783,7 @@ mod test {
|
||||
fn test_entry(){
|
||||
let xs = [(1, 10), (2, 20), (3, 30), (4, 40), (5, 50), (6, 60)];
|
||||
|
||||
let mut map: BTreeMap<_, _> = xs.iter().map(|&x| x).collect();
|
||||
let mut map: BTreeMap<_, _> = xs.iter().cloned().collect();
|
||||
|
||||
// Existing key (insert)
|
||||
match map.entry(1) {
|
||||
|
@ -89,7 +89,7 @@ impl<T: Ord> BTreeSet<T> {
|
||||
/// ```
|
||||
/// use std::collections::BTreeSet;
|
||||
///
|
||||
/// let mut set: BTreeSet<int> = BTreeSet::new();
|
||||
/// let mut set: BTreeSet<i32> = BTreeSet::new();
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn new() -> BTreeSet<T> {
|
||||
@ -114,13 +114,13 @@ impl<T> BTreeSet<T> {
|
||||
/// ```
|
||||
/// use std::collections::BTreeSet;
|
||||
///
|
||||
/// let set: BTreeSet<usize> = [1, 2, 3, 4].iter().map(|&x| x).collect();
|
||||
/// let set: BTreeSet<usize> = [1, 2, 3, 4].iter().cloned().collect();
|
||||
///
|
||||
/// for x in set.iter() {
|
||||
/// println!("{}", x);
|
||||
/// }
|
||||
///
|
||||
/// let v: Vec<usize> = set.iter().map(|&x| x).collect();
|
||||
/// let v: Vec<usize> = set.iter().cloned().collect();
|
||||
/// assert_eq!(v, vec![1,2,3,4]);
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@ -135,7 +135,7 @@ impl<T> BTreeSet<T> {
|
||||
/// ```
|
||||
/// use std::collections::BTreeSet;
|
||||
///
|
||||
/// let set: BTreeSet<usize> = [1, 2, 3, 4].iter().map(|&x| x).collect();
|
||||
/// let set: BTreeSet<usize> = [1, 2, 3, 4].iter().cloned().collect();
|
||||
///
|
||||
/// let v: Vec<usize> = set.into_iter().collect();
|
||||
/// assert_eq!(v, vec![1,2,3,4]);
|
||||
@ -331,7 +331,7 @@ impl<T: Ord> BTreeSet<T> {
|
||||
/// ```
|
||||
/// use std::collections::BTreeSet;
|
||||
///
|
||||
/// let set: BTreeSet<int> = [1, 2, 3].iter().map(|&x| x).collect();
|
||||
/// let set: BTreeSet<_> = [1, 2, 3].iter().cloned().collect();
|
||||
/// assert_eq!(set.contains(&1), true);
|
||||
/// assert_eq!(set.contains(&4), false);
|
||||
/// ```
|
||||
@ -348,8 +348,8 @@ impl<T: Ord> BTreeSet<T> {
|
||||
/// ```
|
||||
/// use std::collections::BTreeSet;
|
||||
///
|
||||
/// let a: BTreeSet<int> = [1, 2, 3].iter().map(|&x| x).collect();
|
||||
/// let mut b: BTreeSet<int> = BTreeSet::new();
|
||||
/// let a: BTreeSet<_> = [1, 2, 3].iter().cloned().collect();
|
||||
/// let mut b = BTreeSet::new();
|
||||
///
|
||||
/// assert_eq!(a.is_disjoint(&b), true);
|
||||
/// b.insert(4);
|
||||
@ -369,8 +369,8 @@ impl<T: Ord> BTreeSet<T> {
|
||||
/// ```
|
||||
/// use std::collections::BTreeSet;
|
||||
///
|
||||
/// let sup: BTreeSet<int> = [1, 2, 3].iter().map(|&x| x).collect();
|
||||
/// let mut set: BTreeSet<int> = BTreeSet::new();
|
||||
/// let sup: BTreeSet<_> = [1, 2, 3].iter().cloned().collect();
|
||||
/// let mut set = BTreeSet::new();
|
||||
///
|
||||
/// assert_eq!(set.is_subset(&sup), true);
|
||||
/// set.insert(2);
|
||||
@ -411,8 +411,8 @@ impl<T: Ord> BTreeSet<T> {
|
||||
/// ```
|
||||
/// use std::collections::BTreeSet;
|
||||
///
|
||||
/// let sub: BTreeSet<int> = [1, 2].iter().map(|&x| x).collect();
|
||||
/// let mut set: BTreeSet<int> = BTreeSet::new();
|
||||
/// let sub: BTreeSet<_> = [1, 2].iter().cloned().collect();
|
||||
/// let mut set = BTreeSet::new();
|
||||
///
|
||||
/// assert_eq!(set.is_superset(&sub), false);
|
||||
///
|
||||
@ -525,11 +525,11 @@ impl<'a, 'b, T: Ord + Clone> Sub<&'b BTreeSet<T>> for &'a BTreeSet<T> {
|
||||
/// ```
|
||||
/// use std::collections::BTreeSet;
|
||||
///
|
||||
/// let a: BTreeSet<int> = vec![1, 2, 3].into_iter().collect();
|
||||
/// let b: BTreeSet<int> = vec![3, 4, 5].into_iter().collect();
|
||||
/// let a: BTreeSet<_> = vec![1, 2, 3].into_iter().collect();
|
||||
/// let b: BTreeSet<_> = vec![3, 4, 5].into_iter().collect();
|
||||
///
|
||||
/// let result: BTreeSet<int> = &a - &b;
|
||||
/// let result_vec: Vec<int> = result.into_iter().collect();
|
||||
/// let result = &a - &b;
|
||||
/// let result_vec: Vec<_> = result.into_iter().collect();
|
||||
/// assert_eq!(result_vec, vec![1, 2]);
|
||||
/// ```
|
||||
fn sub(self, rhs: &BTreeSet<T>) -> BTreeSet<T> {
|
||||
@ -548,11 +548,11 @@ impl<'a, 'b, T: Ord + Clone> BitXor<&'b BTreeSet<T>> for &'a BTreeSet<T> {
|
||||
/// ```
|
||||
/// use std::collections::BTreeSet;
|
||||
///
|
||||
/// let a: BTreeSet<int> = vec![1, 2, 3].into_iter().collect();
|
||||
/// let b: BTreeSet<int> = vec![2, 3, 4].into_iter().collect();
|
||||
/// let a: BTreeSet<_> = vec![1, 2, 3].into_iter().collect();
|
||||
/// let b: BTreeSet<_> = vec![2, 3, 4].into_iter().collect();
|
||||
///
|
||||
/// let result: BTreeSet<int> = &a ^ &b;
|
||||
/// let result_vec: Vec<int> = result.into_iter().collect();
|
||||
/// let result = &a ^ &b;
|
||||
/// let result_vec: Vec<_> = result.into_iter().collect();
|
||||
/// assert_eq!(result_vec, vec![1, 4]);
|
||||
/// ```
|
||||
fn bitxor(self, rhs: &BTreeSet<T>) -> BTreeSet<T> {
|
||||
@ -571,11 +571,11 @@ impl<'a, 'b, T: Ord + Clone> BitAnd<&'b BTreeSet<T>> for &'a BTreeSet<T> {
|
||||
/// ```
|
||||
/// use std::collections::BTreeSet;
|
||||
///
|
||||
/// let a: BTreeSet<int> = vec![1, 2, 3].into_iter().collect();
|
||||
/// let b: BTreeSet<int> = vec![2, 3, 4].into_iter().collect();
|
||||
/// let a: BTreeSet<_> = vec![1, 2, 3].into_iter().collect();
|
||||
/// let b: BTreeSet<_> = vec![2, 3, 4].into_iter().collect();
|
||||
///
|
||||
/// let result: BTreeSet<int> = &a & &b;
|
||||
/// let result_vec: Vec<int> = result.into_iter().collect();
|
||||
/// let result = &a & &b;
|
||||
/// let result_vec: Vec<_> = result.into_iter().collect();
|
||||
/// assert_eq!(result_vec, vec![2, 3]);
|
||||
/// ```
|
||||
fn bitand(self, rhs: &BTreeSet<T>) -> BTreeSet<T> {
|
||||
@ -594,11 +594,11 @@ impl<'a, 'b, T: Ord + Clone> BitOr<&'b BTreeSet<T>> for &'a BTreeSet<T> {
|
||||
/// ```
|
||||
/// use std::collections::BTreeSet;
|
||||
///
|
||||
/// let a: BTreeSet<int> = vec![1, 2, 3].into_iter().collect();
|
||||
/// let b: BTreeSet<int> = vec![3, 4, 5].into_iter().collect();
|
||||
/// let a: BTreeSet<_> = vec![1, 2, 3].into_iter().collect();
|
||||
/// let b: BTreeSet<_> = vec![3, 4, 5].into_iter().collect();
|
||||
///
|
||||
/// let result: BTreeSet<int> = &a | &b;
|
||||
/// let result_vec: Vec<int> = result.into_iter().collect();
|
||||
/// let result = &a | &b;
|
||||
/// let result_vec: Vec<_> = result.into_iter().collect();
|
||||
/// assert_eq!(result_vec, vec![1, 2, 3, 4, 5]);
|
||||
/// ```
|
||||
fn bitor(self, rhs: &BTreeSet<T>) -> BTreeSet<T> {
|
||||
|
@ -756,7 +756,7 @@ impl<'a, A> IterMut<'a, A> {
|
||||
/// ```
|
||||
/// use std::collections::DList;
|
||||
///
|
||||
/// let mut list: DList<int> = vec![1, 3, 4].into_iter().collect();
|
||||
/// let mut list: DList<_> = vec![1, 3, 4].into_iter().collect();
|
||||
///
|
||||
/// {
|
||||
/// let mut it = list.iter_mut();
|
||||
@ -765,7 +765,7 @@ impl<'a, A> IterMut<'a, A> {
|
||||
/// it.insert_next(2);
|
||||
/// }
|
||||
/// {
|
||||
/// let vec: Vec<int> = list.into_iter().collect();
|
||||
/// let vec: Vec<_> = list.into_iter().collect();
|
||||
/// assert_eq!(vec, vec![1, 2, 3, 4]);
|
||||
/// }
|
||||
/// ```
|
||||
@ -783,7 +783,7 @@ impl<'a, A> IterMut<'a, A> {
|
||||
/// ```
|
||||
/// use std::collections::DList;
|
||||
///
|
||||
/// let mut list: DList<int> = vec![1, 2, 3].into_iter().collect();
|
||||
/// let mut list: DList<_> = vec![1, 2, 3].into_iter().collect();
|
||||
///
|
||||
/// let mut it = list.iter_mut();
|
||||
/// assert_eq!(it.next().unwrap(), &1);
|
||||
|
@ -108,7 +108,7 @@
|
||||
//! There are various parameters which do require a particular type, however.
|
||||
//! Namely if the syntax `{:.*}` is used, then the number of characters to print
|
||||
//! precedes the actual object being formatted, and the number of characters
|
||||
//! must have the type `uint`. Although a `uint` can be printed with `{}`, it is
|
||||
//! must have the type `usize`. Although a `usize` can be printed with `{}`, it is
|
||||
//! illegal to reference an argument as such. For example this is another
|
||||
//! invalid format string:
|
||||
//!
|
||||
@ -121,7 +121,7 @@
|
||||
//! When requesting that an argument be formatted with a particular type, you
|
||||
//! are actually requesting that an argument ascribes to a particular trait.
|
||||
//! This allows multiple actual types to be formatted via `{:x}` (like `i8` as
|
||||
//! well as `int`). The current mapping of types to traits is:
|
||||
//! well as `isize`). The current mapping of types to traits is:
|
||||
//!
|
||||
//! * *nothing* ⇒ `Display`
|
||||
//! * `?` ⇒ `Debug`
|
||||
@ -173,8 +173,8 @@
|
||||
//!
|
||||
//! #[derive(Debug)]
|
||||
//! struct Vector2D {
|
||||
//! x: int,
|
||||
//! y: int,
|
||||
//! x: isize,
|
||||
//! y: isize,
|
||||
//! }
|
||||
//!
|
||||
//! impl fmt::Display for Vector2D {
|
||||
@ -380,9 +380,9 @@
|
||||
//! the '0' flag is specified for numerics, then the implicit fill character is
|
||||
//! '0'.
|
||||
//!
|
||||
//! The value for the width can also be provided as a `uint` in the list of
|
||||
//! The value for the width can also be provided as a `usize` in the list of
|
||||
//! parameters by using the `2$` syntax indicating that the second argument is a
|
||||
//! `uint` specifying the width.
|
||||
//! `usize` specifying the width.
|
||||
//!
|
||||
//! ### Precision
|
||||
//!
|
||||
|
@ -73,7 +73,7 @@
|
||||
//!
|
||||
//! The method `iter()` returns an iteration value for a slice. The iterator
|
||||
//! yields references to the slice's elements, so if the element
|
||||
//! type of the slice is `int`, the element type of the iterator is `&int`.
|
||||
//! type of the slice is `isize`, the element type of the iterator is `&isize`.
|
||||
//!
|
||||
//! ```rust
|
||||
//! let numbers = [0, 1, 2];
|
||||
@ -1218,7 +1218,7 @@ impl Iterator for ElementSwaps {
|
||||
// Find the index of the largest mobile element:
|
||||
// The direction should point into the vector, and the
|
||||
// swap should be with a smaller `size` element.
|
||||
let max = self.sdir.iter().map(|&x| x).enumerate()
|
||||
let max = self.sdir.iter().cloned().enumerate()
|
||||
.filter(|&(i, sd)|
|
||||
new_pos(i, sd.dir) < self.sdir.len() &&
|
||||
self.sdir[new_pos(i, sd.dir)].size < sd.size)
|
||||
|
@ -2705,22 +2705,22 @@ mod tests {
|
||||
|
||||
for &(s, g) in &test_same[] {
|
||||
// test forward iterator
|
||||
assert!(order::equals(s.graphemes(true), g.iter().map(|&x| x)));
|
||||
assert!(order::equals(s.graphemes(false), g.iter().map(|&x| x)));
|
||||
assert!(order::equals(s.graphemes(true), g.iter().cloned()));
|
||||
assert!(order::equals(s.graphemes(false), g.iter().cloned()));
|
||||
|
||||
// test reverse iterator
|
||||
assert!(order::equals(s.graphemes(true).rev(), g.iter().rev().map(|&x| x)));
|
||||
assert!(order::equals(s.graphemes(false).rev(), g.iter().rev().map(|&x| x)));
|
||||
assert!(order::equals(s.graphemes(true).rev(), g.iter().rev().cloned()));
|
||||
assert!(order::equals(s.graphemes(false).rev(), g.iter().rev().cloned()));
|
||||
}
|
||||
|
||||
for &(s, gt, gf) in &test_diff {
|
||||
// test forward iterator
|
||||
assert!(order::equals(s.graphemes(true), gt.iter().map(|&x| x)));
|
||||
assert!(order::equals(s.graphemes(false), gf.iter().map(|&x| x)));
|
||||
assert!(order::equals(s.graphemes(true), gt.iter().cloned()));
|
||||
assert!(order::equals(s.graphemes(false), gf.iter().cloned()));
|
||||
|
||||
// test reverse iterator
|
||||
assert!(order::equals(s.graphemes(true).rev(), gt.iter().rev().map(|&x| x)));
|
||||
assert!(order::equals(s.graphemes(false).rev(), gf.iter().rev().map(|&x| x)));
|
||||
assert!(order::equals(s.graphemes(true).rev(), gt.iter().rev().cloned()));
|
||||
assert!(order::equals(s.graphemes(false).rev(), gf.iter().rev().cloned()));
|
||||
}
|
||||
|
||||
// test the indices iterators
|
||||
|
@ -158,7 +158,7 @@ impl<T> Vec<T> {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// let mut vec: Vec<int> = Vec::new();
|
||||
/// let mut vec: Vec<i32> = Vec::new();
|
||||
/// ```
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@ -277,7 +277,7 @@ impl<T> Vec<T> {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// let vec: Vec<int> = Vec::with_capacity(10);
|
||||
/// let vec: Vec<i32> = Vec::with_capacity(10);
|
||||
/// assert_eq!(vec.capacity(), 10);
|
||||
/// ```
|
||||
#[inline]
|
||||
@ -296,7 +296,7 @@ impl<T> Vec<T> {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// let mut vec: Vec<int> = vec![1];
|
||||
/// let mut vec = vec![1];
|
||||
/// vec.reserve(10);
|
||||
/// assert!(vec.capacity() >= 11);
|
||||
/// ```
|
||||
@ -325,7 +325,7 @@ impl<T> Vec<T> {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// let mut vec: Vec<int> = vec![1];
|
||||
/// let mut vec = vec![1];
|
||||
/// vec.reserve_exact(10);
|
||||
/// assert!(vec.capacity() >= 11);
|
||||
/// ```
|
||||
@ -347,7 +347,7 @@ impl<T> Vec<T> {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// let mut vec: Vec<int> = Vec::with_capacity(10);
|
||||
/// let mut vec = Vec::with_capacity(10);
|
||||
/// vec.push_all(&[1, 2, 3]);
|
||||
/// assert_eq!(vec.capacity(), 10);
|
||||
/// vec.shrink_to_fit();
|
||||
@ -424,7 +424,7 @@ impl<T> Vec<T> {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// fn foo(slice: &mut [int]) {}
|
||||
/// fn foo(slice: &mut [i32]) {}
|
||||
///
|
||||
/// let mut vec = vec![1, 2];
|
||||
/// foo(vec.as_mut_slice());
|
||||
@ -845,7 +845,7 @@ impl<T> Vec<T> {
|
||||
// This `as isize` cast is safe, because the size of the elements of the
|
||||
// vector is not 0, and:
|
||||
//
|
||||
// 1) If the size of the elements in the vector is 1, the `int` may
|
||||
// 1) If the size of the elements in the vector is 1, the `isize` may
|
||||
// overflow, but it has the correct bit pattern so that the
|
||||
// `.offset()` function will work.
|
||||
//
|
||||
@ -858,7 +858,7 @@ impl<T> Vec<T> {
|
||||
// (0x1 + 0x8 = 0x1 - 0x8)
|
||||
//
|
||||
// 2) If the size of the elements in the vector is >1, the `usize` ->
|
||||
// `int` conversion can't overflow.
|
||||
// `isize` conversion can't overflow.
|
||||
let offset = vec.len() as isize;
|
||||
let start = vec.as_mut_ptr();
|
||||
|
||||
@ -1518,7 +1518,7 @@ impl<T> AsSlice<T> for Vec<T> {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// fn foo(slice: &[int]) {}
|
||||
/// fn foo(slice: &[i32]) {}
|
||||
///
|
||||
/// let vec = vec![1, 2];
|
||||
/// foo(vec.as_slice());
|
||||
@ -2162,7 +2162,7 @@ mod tests {
|
||||
fn test_zip_unzip() {
|
||||
let z1 = vec![(1, 4), (2, 5), (3, 6)];
|
||||
|
||||
let (left, right): (Vec<_>, Vec<_>) = z1.iter().map(|&x| x).unzip();
|
||||
let (left, right): (Vec<_>, Vec<_>) = z1.iter().cloned().unzip();
|
||||
|
||||
assert_eq!((1, 4), (left[0], right[0]));
|
||||
assert_eq!((2, 5), (left[1], right[1]));
|
||||
|
@ -104,7 +104,7 @@ impl<T: Hash<Hasher> + Eq> HashSet<T, RandomState> {
|
||||
///
|
||||
/// ```
|
||||
/// use std::collections::HashSet;
|
||||
/// let mut set: HashSet<int> = HashSet::new();
|
||||
/// let mut set: HashSet<i32> = HashSet::new();
|
||||
/// ```
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@ -119,7 +119,7 @@ impl<T: Hash<Hasher> + Eq> HashSet<T, RandomState> {
|
||||
///
|
||||
/// ```
|
||||
/// use std::collections::HashSet;
|
||||
/// let mut set: HashSet<int> = HashSet::with_capacity(10);
|
||||
/// let mut set: HashSet<i32> = HashSet::with_capacity(10);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@ -187,7 +187,7 @@ impl<T, S, H> HashSet<T, S>
|
||||
///
|
||||
/// ```
|
||||
/// use std::collections::HashSet;
|
||||
/// let set: HashSet<int> = HashSet::with_capacity(100);
|
||||
/// let set: HashSet<i32> = HashSet::with_capacity(100);
|
||||
/// assert!(set.capacity() >= 100);
|
||||
/// ```
|
||||
#[inline]
|
||||
@ -208,7 +208,7 @@ impl<T, S, H> HashSet<T, S>
|
||||
///
|
||||
/// ```
|
||||
/// use std::collections::HashSet;
|
||||
/// let mut set: HashSet<int> = HashSet::new();
|
||||
/// let mut set: HashSet<i32> = HashSet::new();
|
||||
/// set.reserve(10);
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@ -225,7 +225,7 @@ impl<T, S, H> HashSet<T, S>
|
||||
/// ```
|
||||
/// use std::collections::HashSet;
|
||||
///
|
||||
/// let mut set: HashSet<int> = HashSet::with_capacity(100);
|
||||
/// let mut set = HashSet::with_capacity(100);
|
||||
/// set.insert(1);
|
||||
/// set.insert(2);
|
||||
/// assert!(set.capacity() >= 100);
|
||||
@ -292,21 +292,21 @@ impl<T, S, H> HashSet<T, S>
|
||||
///
|
||||
/// ```
|
||||
/// use std::collections::HashSet;
|
||||
/// let a: HashSet<int> = [1, 2, 3].iter().map(|&x| x).collect();
|
||||
/// let b: HashSet<int> = [4, 2, 3, 4].iter().map(|&x| x).collect();
|
||||
/// let a: HashSet<_> = [1, 2, 3].iter().cloned().collect();
|
||||
/// let b: HashSet<_> = [4, 2, 3, 4].iter().cloned().collect();
|
||||
///
|
||||
/// // Can be seen as `a - b`.
|
||||
/// for x in a.difference(&b) {
|
||||
/// println!("{}", x); // Print 1
|
||||
/// }
|
||||
///
|
||||
/// let diff: HashSet<int> = a.difference(&b).map(|&x| x).collect();
|
||||
/// assert_eq!(diff, [1].iter().map(|&x| x).collect());
|
||||
/// let diff: HashSet<_> = a.difference(&b).cloned().collect();
|
||||
/// assert_eq!(diff, [1].iter().cloned().collect());
|
||||
///
|
||||
/// // Note that difference is not symmetric,
|
||||
/// // and `b - a` means something else:
|
||||
/// let diff: HashSet<int> = b.difference(&a).map(|&x| x).collect();
|
||||
/// assert_eq!(diff, [4].iter().map(|&x| x).collect());
|
||||
/// let diff: HashSet<_> = b.difference(&a).cloned().collect();
|
||||
/// assert_eq!(diff, [4].iter().cloned().collect());
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn difference<'a>(&'a self, other: &'a HashSet<T, S>) -> Difference<'a, T, S> {
|
||||
@ -322,19 +322,19 @@ impl<T, S, H> HashSet<T, S>
|
||||
///
|
||||
/// ```
|
||||
/// use std::collections::HashSet;
|
||||
/// let a: HashSet<int> = [1, 2, 3].iter().map(|&x| x).collect();
|
||||
/// let b: HashSet<int> = [4, 2, 3, 4].iter().map(|&x| x).collect();
|
||||
/// let a: HashSet<_> = [1, 2, 3].iter().cloned().collect();
|
||||
/// let b: HashSet<_> = [4, 2, 3, 4].iter().cloned().collect();
|
||||
///
|
||||
/// // Print 1, 4 in arbitrary order.
|
||||
/// for x in a.symmetric_difference(&b) {
|
||||
/// println!("{}", x);
|
||||
/// }
|
||||
///
|
||||
/// let diff1: HashSet<int> = a.symmetric_difference(&b).map(|&x| x).collect();
|
||||
/// let diff2: HashSet<int> = b.symmetric_difference(&a).map(|&x| x).collect();
|
||||
/// let diff1: HashSet<_> = a.symmetric_difference(&b).cloned().collect();
|
||||
/// let diff2: HashSet<_> = b.symmetric_difference(&a).cloned().collect();
|
||||
///
|
||||
/// assert_eq!(diff1, diff2);
|
||||
/// assert_eq!(diff1, [1, 4].iter().map(|&x| x).collect());
|
||||
/// assert_eq!(diff1, [1, 4].iter().cloned().collect());
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn symmetric_difference<'a>(&'a self, other: &'a HashSet<T, S>)
|
||||
@ -348,16 +348,16 @@ impl<T, S, H> HashSet<T, S>
|
||||
///
|
||||
/// ```
|
||||
/// use std::collections::HashSet;
|
||||
/// let a: HashSet<int> = [1, 2, 3].iter().map(|&x| x).collect();
|
||||
/// let b: HashSet<int> = [4, 2, 3, 4].iter().map(|&x| x).collect();
|
||||
/// let a: HashSet<_> = [1, 2, 3].iter().cloned().collect();
|
||||
/// let b: HashSet<_> = [4, 2, 3, 4].iter().cloned().collect();
|
||||
///
|
||||
/// // Print 2, 3 in arbitrary order.
|
||||
/// for x in a.intersection(&b) {
|
||||
/// println!("{}", x);
|
||||
/// }
|
||||
///
|
||||
/// let diff: HashSet<int> = a.intersection(&b).map(|&x| x).collect();
|
||||
/// assert_eq!(diff, [2, 3].iter().map(|&x| x).collect());
|
||||
/// let diff: HashSet<_> = a.intersection(&b).cloned().collect();
|
||||
/// assert_eq!(diff, [2, 3].iter().cloned().collect());
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn intersection<'a>(&'a self, other: &'a HashSet<T, S>) -> Intersection<'a, T, S> {
|
||||
@ -373,16 +373,16 @@ impl<T, S, H> HashSet<T, S>
|
||||
///
|
||||
/// ```
|
||||
/// use std::collections::HashSet;
|
||||
/// let a: HashSet<int> = [1, 2, 3].iter().map(|&x| x).collect();
|
||||
/// let b: HashSet<int> = [4, 2, 3, 4].iter().map(|&x| x).collect();
|
||||
/// let a: HashSet<_> = [1, 2, 3].iter().cloned().collect();
|
||||
/// let b: HashSet<_> = [4, 2, 3, 4].iter().cloned().collect();
|
||||
///
|
||||
/// // Print 1, 2, 3, 4 in arbitrary order.
|
||||
/// for x in a.union(&b) {
|
||||
/// println!("{}", x);
|
||||
/// }
|
||||
///
|
||||
/// let diff: HashSet<int> = a.union(&b).map(|&x| x).collect();
|
||||
/// assert_eq!(diff, [1, 2, 3, 4].iter().map(|&x| x).collect());
|
||||
/// let diff: HashSet<_> = a.union(&b).cloned().collect();
|
||||
/// assert_eq!(diff, [1, 2, 3, 4].iter().cloned().collect());
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn union<'a>(&'a self, other: &'a HashSet<T, S>) -> Union<'a, T, S> {
|
||||
|
@ -65,8 +65,8 @@
|
||||
//! * You want a sorted map.
|
||||
//!
|
||||
//! ### Use a `VecMap` when:
|
||||
//! * You want a `HashMap` but with known to be small `uint` keys.
|
||||
//! * You want a `BTreeMap`, but with known to be small `uint` keys.
|
||||
//! * You want a `HashMap` but with known to be small `usize` keys.
|
||||
//! * You want a `BTreeMap`, but with known to be small `usize` keys.
|
||||
//!
|
||||
//! ### Use the `Set` variant of any of these `Map`s when:
|
||||
//! * You just want to remember which keys you've seen.
|
||||
@ -243,7 +243,7 @@
|
||||
//! use std::collections::RingBuf;
|
||||
//!
|
||||
//! let vec = vec![1, 2, 3, 4];
|
||||
//! let buf: RingBuf<uint> = vec.into_iter().collect();
|
||||
//! let buf: RingBuf<_> = vec.into_iter().collect();
|
||||
//! ```
|
||||
//!
|
||||
//! Iterators also provide a series of *adapter* methods for performing common tasks to
|
||||
|
Loading…
Reference in New Issue
Block a user