"由于类型归属而在这里期待类型"

时间:2018-06-08 04:47:16

标签: rust

我有一些代码试图将字符串列表读入struct值。使用下面的代码,我尝试只打印来自input_filePOLIR::generate_config()向量的行。我收到了错误:

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);
}

1 个答案:

答案 0 :(得分:2)

通过从POLIR::generate_config()删除冒号来解决此错误:

fn generate_config(&self, args: Vec<String>) {
    for line in args {
        println!{"{}", line};
    }
}