Cannot infer type for type parameter `T` declared on the struct `Vec`

    println!("\n\nReading World Data...\n\n");
    let mut world_data_string = String::new();
    world.read_to_string(&mut world_data_string).unwrap();
    let mut world_data: Vec<char> = world_data_string.chars().collect();

    let mut tile_list_pusher = vec![];


    for o in file_list_indexer {
        tile_list_pusher.push(&world_data[0..o * 5000 + 1]);
    }

Result:

The compiler needs to know the type of the elements that go in the Vec, even if nothing is ever put into the Vec.

The line in question doesn’t seem to be in the snippet, though.

I am making a 2d array that is filled with Chars, if that helps.

Try giving the compiler an explicit type when you declare the vector. I’m typing on mobile but it should look something like this.

let mut list: Vec<Vec<char>> = vec[]!;
1 Like

Same error after being told by the compiler to add .to_vec()

There's not enough context to help effectively. See if you can reproduce it in the playground (and then use the Share link to share it with us here).

1 Like

OK, here us the link to the code

A reproduction is more like this -- i.e. it reproduces the same error. I had some time to thin it down, but you'll generally get better (free) help if you put some more effort in yourself.

Anyway, you declare tile_set but never use it. Rust is statically typed, and the compiler will error if it can't determine the type at compile time. Either comment it out for now, give it an explicit type, or use it in such a way that the compiler can see what you're going to put into it.

    // Will need this later
    // let mut tile_list = vec![];
    let mut tile_list: Vec<char> = vec![];
    let mut tile_list = tile_list_pusher[0].clone();
1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.