Rust エラー「error[E0425]: cannot find value xxx in this scope」が発生した場合の対処法
![Rust エラー「error[E0425]: cannot find value xxx in this scope」が発生した場合の対処法](https://mebee.info/wp-content/uploads/2019/11/rust.png)
Rustで、エラー「error[E0425]: cannot find value xxx in this scope」が発生した場合の対処法を記述してます。Rustのバージョンは1.62.0を使用してます。
環境
- OS windows11 home
- rustc 1.62.0
エラー全文
以下のコードで発生
fn main() {
let str: String = "mebee".to_string();
println!("{}", foo);
}
エラー全文
error[E0425]: cannot find value `foo` in this scope
--> sample.rs:5:20
|
5 | println!("{}", foo);
| ^^^ not found in this scope
error: aborting due to previous error
原因
「foo」が定義されていないため
対処法
「foo」を定義する
fn main() {
let foo: String = "mebee".to_string();
println!("{}", foo);
}
実行結果

-
前の記事
javascript includesで大文字・小文字を区別せずに文字列に指定した文字列が含まれているかを判定する 2022.10.08
-
次の記事
gmail スター付きのメッセージに移動するショートカットキー 2022.10.08
コメントを書く