Why is there an inconsistency with the array and vector when defining its datatype?

So say if I define an array and a vector

fn main()
{
    let array: [i32; 3] = [1,2,3];
    let vector: Vec<i32> = vec![1,2,3];
}

How come when defining the datatype for the vector the syntax is different compared to defining an array?

Because vector is an ordinary struct, and array type is a special syntax construction. As for why this is the case - well, the one obvious reason is that the array length is part of its type: if we had working const generics, array could be an ordinary struct too, with its length as generic parameter.

How is vector a struct though?

Literally.

6 Likes

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.