2021-02-04 12:08:08 -06:00
|
|
|
// run-rustfix
|
|
|
|
|
2020-09-10 13:18:23 -05:00
|
|
|
#![warn(clippy::from_iter_instead_of_collect)]
|
2021-02-04 12:08:08 -06:00
|
|
|
#![allow(unused_imports)]
|
2020-09-10 13:18:23 -05:00
|
|
|
|
2021-02-04 12:08:08 -06:00
|
|
|
use std::collections::{BTreeMap, BTreeSet, HashMap, VecDeque};
|
2020-09-10 13:18:23 -05:00
|
|
|
use std::iter::FromIterator;
|
|
|
|
|
2021-05-22 13:47:11 -05: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 {
|
|
|
|
<Self as FromIterator<bool>>::from_iter(iter.into_iter().copied())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-10 13:18:23 -05:00
|
|
|
fn main() {
|
2020-10-01 11:04:05 -05:00
|
|
|
let iter_expr = std::iter::repeat(5).take(5);
|
2021-02-04 12:08:08 -06:00
|
|
|
let _ = Vec::from_iter(iter_expr);
|
2020-10-01 11:34:36 -05:00
|
|
|
|
2021-02-04 12:08:08 -06:00
|
|
|
let _ = HashMap::<usize, &i8>::from_iter(vec![5, 5, 5, 5].iter().enumerate());
|
2020-10-12 10:27:50 -05:00
|
|
|
|
|
|
|
Vec::from_iter(vec![42u32]);
|
2021-01-31 14:43:35 -06:00
|
|
|
|
|
|
|
let a = vec![0, 1, 2];
|
|
|
|
assert_eq!(a, Vec::from_iter(0..3));
|
2021-02-09 10:38:16 -06:00
|
|
|
assert_eq!(a, Vec::<i32>::from_iter(0..3));
|
2021-01-31 14:43:35 -06:00
|
|
|
|
|
|
|
let mut b = VecDeque::from_iter(0..3);
|
|
|
|
b.push_back(4);
|
2021-02-04 12:08:08 -06:00
|
|
|
|
2021-02-09 10:38:16 -06:00
|
|
|
let mut b = VecDeque::<i32>::from_iter(0..3);
|
|
|
|
b.push_back(4);
|
|
|
|
|
|
|
|
{
|
|
|
|
use std::collections;
|
|
|
|
let mut b = collections::VecDeque::<i32>::from_iter(0..3);
|
|
|
|
b.push_back(4);
|
|
|
|
}
|
|
|
|
|
2021-02-04 12:08:08 -06:00
|
|
|
let values = [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'd')];
|
|
|
|
let bm = BTreeMap::from_iter(values.iter().cloned());
|
|
|
|
let mut bar = BTreeMap::from_iter(bm.range(0..2));
|
|
|
|
bar.insert(&4, &'e');
|
|
|
|
|
|
|
|
let mut bts = BTreeSet::from_iter(0..3);
|
|
|
|
bts.insert(2);
|
|
|
|
{
|
|
|
|
use std::collections;
|
|
|
|
let _ = collections::BTreeSet::from_iter(0..3);
|
2021-02-09 10:38:16 -06:00
|
|
|
let _ = collections::BTreeSet::<u32>::from_iter(0..3);
|
2021-02-04 12:08:08 -06:00
|
|
|
}
|
2021-02-09 10:38:16 -06:00
|
|
|
|
|
|
|
for _i in Vec::from_iter([1, 2, 3].iter()) {}
|
|
|
|
for _i in Vec::<&i32>::from_iter([1, 2, 3].iter()) {}
|
2020-09-10 13:18:23 -05:00
|
|
|
}
|