打印切片矢量结果"尺寸不满意"

时间:2016-12-09 12:25:02

标签: rust

我正在尝试切片矢量并在Rust中同时打印它。这是我的代码:

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

错误:

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

如何打印此切片矢量?

1 个答案:

答案 0 :(得分:7)

您需要使用参考;它在Rust 1.13中对我有用。

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