我正在尝试切片矢量并在Rust中同时打印它.这是我的代码:
fn main() {
let a = vec![1, 2, 3, 4];
println!("{:?}", a[1..2]);
}
Run Code Online (Sandbox Code Playgroud)
错误:
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
Run Code Online (Sandbox Code Playgroud)
如何打印此切片矢量?
小智 7
你需要使用一个参考; 它在Rust 1.13中对我有用.
println!("{:?}", &a[1..3]);
Run Code Online (Sandbox Code Playgroud)