为什么以下带有char范围的循环无法编译?
fn main() {
for c in 'a'..'z' {
println!("{}", c);
}
}
Run Code Online (Sandbox Code Playgroud)
错误...
main.rs:11:5: 14:2 error: the trait `core::num::One` is not implemented for the type `char` [E0277]
main.rs:11 for c in 'a'..'z' {
main.rs:12 println!("{}", c);
main.rs:13 }
main.rs:14 }
main.rs:11:5: 14:2 error: the trait `core::iter::Step` is not implemented for the type `char` [E0277]
main.rs:11 for c in 'a'..'z' {
main.rs:12 println!("{}", c);
main.rs:13 }
main.rs:14 }
Run Code Online (Sandbox Code Playgroud)
为什么你甚至需要core::num::One迭代一个范围?
rust ×1