【发布时间】:2019-10-11 07:20:14
【问题描述】:
我是 Rust 新手,发现了一些我无法反驳的东西。
当我写作时
fn main() {
('a'..'z').all(|_| true);
}
编译器报错:
error[E0599]: no method named `all` found for type `std::ops::Range<char>` in the current scope
--> src/main.rs:2:16
|
2 | ('a'..'z').all(|_| true)
| ^^^
|
= note: the method `all` exists but the following trait bounds were not satisfied:
`std::ops::Range<char> : std::iter::Iterator`
当我把它改成
fn main() {
(b'a'..b'z').all(|_| true);
}
它编译。
这里发生了什么? Rust 说 the method ... exists but the following trait bounds were not satisfied 是什么意思?
【问题讨论】:
-
你可以映射到一个char来实现你想要的,例如:play.rust-lang.org/…
标签: rust