[英]Print sliced vector results in “Sized is not satisfied”
我正在嘗試切片矢量並在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
如何打印此切片矢量?
你需要使用一個參考; 它在Rust 1.13中對我有用。
println!("{:?}", &a[1..3]);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.