rust
1fn test(b: String) -> String { 2 *(&b) 3} 4 5fn main() { 6 println!("{}", test("This is the test.".to_string())); 7}
上記のコードを実行したところ以下のエラーが発生しました。
terminal
1Compiling playground v0.0.1 (/playground) 2error[E0507]: cannot move out of a shared reference 3 --> src/main.rs:9:5 4 | 59 | *(&b) 6 | ^^^^^ move occurs because value has type `String`, which does not implement the `Copy` trait 7 8For more information about this error, try `rustc --explain E0507`. 9error: could not compile `playground` due to previous error
これはなぜダメなんでしょうか?
参照を作って外しているだけです。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。