“Expecting a type here because of type ascription”

2019-09-21 05:28发布

I have some code that is attempting to read in a list of strings into struct values. With the code below, I am attempting to just print the lines from the input_file vector from inside POLIR::generate_config(). I am getting the error:

error: expected type, found `{`
 --> src/main.rs:5:27
  |
5 |         for line in args: {
  |                           ^ expecting a type here because of type ascription

What am I doing wrong here?

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

标签: rust
1条回答
The star\"
2楼-- · 2019-09-21 05:58

This error was solved by removing the colon from POLIR::generate_config():

fn generate_config(&self, args: Vec<String>) {
    for line in args {
        println!{"{}", line};
    }
}
查看更多
登录 后发表回答