相关疑难解决方法(0)

为什么num :: One需要迭代一个范围?

为什么以下带有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

2
推荐指数
1
解决办法
822
查看次数

标签 统计

rust ×1