I have a Vec
of structs and I want to get the ones from position x to y:
fn main() {
#[derive(Debug)]
struct A {
name: String,
}
let x = A { name: "X".to_string() };
let y = A { name: "Y".to_string() };
let z = A { name: "Z".to_string() };
let v = vec!(x,y,z);
println!("{:?}", v[0..1]);
}
Here's the Rust Playground link for it.
I'm getting the error:
error[E0277]: the size for values of type `[A]` cannot be known at compilation time
--> src/main.rs:13:5
|
13 | println!("{:?}", v[0..1]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
How can I make sure the size is known at compile time? I couldn't find any obvious answer, therefore I think I'm missing something fundamental.