Logo

Programming-Idioms

History of Idiom 118 > diff from v46 to v47

Edit summary for version 47 by Plecra:
[Rust] Rust's turbofish isn't considered idiomatic

Version 46

2020-07-05, 20:31:37

Version 47

2020-07-15, 16:41:47

Idiom #118 List to set

Create set y from list x.
x may contain duplicates. y is unordered and has no repeated values.

Idiom #118 List to set

Create set y from list x.
x may contain duplicates. y is unordered and has no repeated values.

Variables
y,x
Variables
y,x
Imports
use std::collections::HashSet;
Imports
use std::collections::HashSet;
Code
let y = x.iter().cloned().collect::<HashSet<_>>();
Code
let y: HashSet<_> = x.into_iter().collect();
Demo URL
https://play.rust-lang.org/?gist=1537592becb114e5b6f11b161f48ec05&version=stable&backtrace=0