Printing sliced ​​vector results in "Size not performed"

I am trying to cut a vector and print it at the same time in Rust. This is my code:

fn main() {
    let a = vec![1, 2, 3, 4];
    println!("{:?}", a[1..2]);
}

Error:

error[E0277]: the trait bound `[{integer}]: std::marker::Sized` is not satisfied
 --> src/main.rs:6:5
  |
6 |     println!("{:?}", a[1..3]);
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `[{integer}]: std::marker::Sized` not satisfied
  |
  = note: `[{integer}]` does not have a constant size known at compile-time
  = note: required by `std::fmt::ArgumentV1::new`
  = note: this error originates in a macro outside of the current crate

How to print this sparse vector?

+4
source share
1 answer

You need to use the link; he worked for me in Rust 1.13.

println!("{:?}", &a[1..3]);
+6
source

Source: https://habr.com/ru/post/1663322/


All Articles