【发布时间】:2018-06-08 04:47:15
【问题描述】:
我有一些代码试图将字符串列表读入结构值。使用下面的代码,我试图从POLIR::generate_config() 内部打印来自input_file 向量的行。我收到错误消息:
error: expected type, found `{`
--> src/main.rs:5:27
|
5 | for line in args: {
| ^ expecting a type here because of type ascription
我在这里做错了什么?
struct POLIR {}
impl POLIR {
fn generate_config(&self, args: Vec<String>) {
for line in args: {
println!{"{}", line};
}
}
}
fn main() {
//other program stuff
let input_file = lines_from_file(input_file);
let system = POLIR {};
POLIR::generate_config(&system, input_file);
}
【问题讨论】:
-
重新读取错误。
"did you mean to use ';' here?". -
我会指给您the book which has examples on using
for...loops 供您查看。您的代码中有一个非常明显的语法错误。 -
啊,我明白了。感谢您的帮助。 @SimonWhitehead
-
python 太多了?
-
Idiomatic Rust 对变量、方法、宏和字段使用
snake_case,对类型使用UpperCamelCase。请改用Polir。
标签: rust