【发布时间】:2019-05-27 01:42:53
【问题描述】:
我正在尝试生成一个包含小写 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。
是否不可能使用一系列字符作为迭代器?如果是这样,为什么?如果没有,我做错了什么?我正在使用稳定的 Rust 2018 1.31.1。
【问题讨论】:
-
你错过了
where A: Step
标签: collections rust iterator