2016-12-09 9 views
4

ベクトルをスライスして同時に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 

答えて

6

参照を使用する必要があります。それは錆1.13で私のために働いた。

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

こんにちは、私は、配列、スライス、ベクトルとボックスの違いを理解しようとしています。あなたはそれのために良いtutsを知っていますか?私は具体的にボックスの仕組みを理解したいと思うし、ベクターがスマートポインタであると言っているときに何を意味するのだろうか。 –

+0

ちょうどこれが見つかりました:https://github.com/nrc/r4cppp/blob/master/arrays.md – anon8112

+0

それは配列、スライス、ベクトルの違いをかなりよく説明しています – anon8112

関連する問題