https://atcoder.jp/contests/abc240/tasks/abc240_b
Traitの指定にwhereを使うとちょっときれいに書けます。
// Count Distinct Integers #![allow(non_snake_case)] use std::collections::HashSet; fn read<T: std::str::FromStr>() -> T { let mut line = String::new(); std::io::stdin().read_line(&mut line).ok(); line.trim().parse().ok().unwrap() } fn read_set<T>() -> HashSet<T> where T: std::str::FromStr + std::cmp::Eq + std::hash::Hash { read::<String>().split_whitespace() .map(|e| e.parse().ok().unwrap()).collect() } fn main() { let _N: usize = read(); let A: HashSet<i32> = read_set(); println!("{}", A.len()) }