0
let s1 = String::from("hello world.");
let r1 = &s1;
let sl1 = &s1[..];
let sl2 = &r1[..];
let sl3 = r1[..];
println!("{}", sl3);
sl1
とsl2
の違いは何ですか、なぜsl3
は無効ですか? r1
は既に参照されていません、なぜ&
が必要ですか?Rustの2つのスライスの違いは何ですか?
[この質問](https://stackoverflow.com/questions/27879161/what-is-the-return-type-of-the-indexing-operation-on-a-slice)の回答にも答えますかあなたですか? –
'sl1'と' sl2'の相違点については何もありません。両方とも 'String'をスライスに逆参照させ、その後スライスを範囲でインデックス化します。 https://stackoverflow.com/q/28519997/279627も参照してください。 –