上級 › E0284: type annotations needed の原因と直し方 › パターン4
E0284: type annotations needed の原因と直し方
parse()のように戻り値の型がジェネリックで、文脈からも型を一意に決められない場合、E0284エラーになります。
1 fn main() { 2 let qty_____ = "7".parse().unwrap(); ^ 3 println!("{}", qty); 4 }
error[E0284]: type annotations needed
空欄を埋めて実行を通す
parseはFromStrを実装しているあらゆる型に変換できる汎用的なメソッドなので、型指定が必須になる場面があります。
次の問題