我试图生成一个包含小写ASCII字符的向量.这种更复杂的方法有效:
let ascii_lowercase = (b'a'..=b'z').map(|b| b as char).collect::<Vec<char>>();
但我一开始提出的这个更直接的方法并不是:
let ascii_lowercase = ('a'..='z').collect::<Vec<char>>();
错误是:
error[E0599]: no method named `collect` found for type `std::ops::RangeInclusive<char>` in the current scope
--> src/main.rs:2:39
|
2 | let ascii_lowercase = ('a'..='z').collect::<Vec<char>>();
| ^^^^^^^
|
= note: the method `collect` exists but the following trait bounds were not satisfied:
`std::ops::RangeInclusive<char> : std::iter::Iterator`
`&mut std::ops::RangeInclusive<char> : std::iter::Iterator`
这很奇怪,因为据我所知,有blanket implementation of Iterator
for RangeInclusive
个.
作为一个不可能使用的字符范围?如果是,为什么?如果不是,我做错了什么?我使用的是stable Rust 2018 1.31.1.