2021-02-04 18:08:08 +00:00
|
|
|
// run-rustfix
|
|
|
|
|
|
|
|
#![warn(clippy::from_iter_instead_of_collect)]
|
|
|
|
#![allow(unused_imports)]
|
|
|
|
|
|
|
|
use std::collections::{BTreeMap, BTreeSet, HashMap, VecDeque};
|
|
|
|
use std::iter::FromIterator;
|
|
|
|
|
2021-05-22 18:47:11 +00:00
|
|
|
struct Foo(Vec<bool>);
|
|
|
|
|
|
|
|
impl FromIterator<bool> for Foo {
|
|
|
|
fn from_iter<T: IntoIterator<Item = bool>>(_: T) -> Self {
|
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> FromIterator<&'a bool> for Foo {
|
|
|
|
fn from_iter<T: IntoIterator<Item = &'a bool>>(iter: T) -> Self {
|
|
|
|
iter.into_iter().copied().collect::<Self>()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-04 18:08:08 +00:00
|
|
|
fn main() {
|
|
|
|
let iter_expr = std::iter::repeat(5).take(5);
|
2021-02-09 16:38:16 +00:00
|
|
|
let _ = iter_expr.collect::<Vec<_>>();
|
2021-02-04 18:08:08 +00:00
|
|
|
|
2021-02-09 16:38:16 +00:00
|
|
|
let _ = vec![5, 5, 5, 5].iter().enumerate().collect::<HashMap<usize, &i8>>();
|
2021-02-04 18:08:08 +00:00
|
|
|
|
|
|
|
Vec::from_iter(vec![42u32]);
|
|
|
|
|
|
|
|
let a = vec![0, 1, 2];
|
2021-02-09 16:38:16 +00:00
|
|
|
assert_eq!(a, (0..3).collect::<Vec<_>>());
|
|
|
|
assert_eq!(a, (0..3).collect::<Vec<i32>>());
|
2021-02-04 18:08:08 +00:00
|
|
|
|
2021-02-09 16:38:16 +00:00
|
|
|
let mut b = (0..3).collect::<VecDeque<_>>();
|
2021-02-04 18:08:08 +00:00
|
|
|
b.push_back(4);
|
|
|
|
|
2021-02-09 16:38:16 +00:00
|
|
|
let mut b = (0..3).collect::<VecDeque<i32>>();
|
|
|
|
b.push_back(4);
|
|
|
|
|
|
|
|
{
|
|
|
|
use std::collections;
|
|
|
|
let mut b = (0..3).collect::<collections::VecDeque<i32>>();
|
|
|
|
b.push_back(4);
|
|
|
|
}
|
|
|
|
|
2021-02-04 18:08:08 +00:00
|
|
|
let values = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'd')];
|
2021-02-09 16:38:16 +00:00
|
|
|
let bm = values.iter().cloned().collect::<BTreeMap<_, _>>();
|
|
|
|
let mut bar = bm.range(0..2).collect::<BTreeMap<_, _>>();
|
2021-02-04 18:08:08 +00:00
|
|
|
bar.insert(&4, &'e');
|
|
|
|
|
2021-02-09 16:38:16 +00:00
|
|
|
let mut bts = (0..3).collect::<BTreeSet<_>>();
|
2021-02-04 18:08:08 +00:00
|
|
|
bts.insert(2);
|
|
|
|
{
|
|
|
|
use std::collections;
|
2021-02-09 16:38:16 +00:00
|
|
|
let _ = (0..3).collect::<collections::BTreeSet<_>>();
|
|
|
|
let _ = (0..3).collect::<collections::BTreeSet<u32>>();
|
2021-02-04 18:08:08 +00:00
|
|
|
}
|
2021-02-09 16:38:16 +00:00
|
|
|
|
|
|
|
for _i in [1, 2, 3].iter().collect::<Vec<_>>() {}
|
|
|
|
for _i in [1, 2, 3].iter().collect::<Vec<&i32>>() {}
|
2021-02-04 18:08:08 +00:00
|
|
|
}
|