前提
tauriを使ってフロントエンドがjs(vue.js)、バックエンド(Rust)のデスクトップアプリを作成してます。
Rustについてはまったくの初学者で初歩の初歩でつまずいてます。
実現したいこと
exeファイルのフルパスをstd::path::Pathの型で取得したいです。
最終的には「[exeファイルのディレクトリ]/tasklist/tasklist.csv」のフルパスを上記のexeファイルのフルパスから生成したいと思ってます。
発生している問題・エラーメッセージ
こちらのコードを実行しようとすると
Rust
1fn read_task_list() { 2 //get task list filepath 3 let exe_pash: &Path = match std::env::current_exe() { 4 Ok(path) => path.as_path(), 5 Err(_e) => Path::new("./"), 6 };
このようなエラーが出ます。
path変数のライフタイムがOk(path) => path.as_path(),で終わってしまうのに外側の変数に値を代入しようとしてるからだと思います。(Rustの用語とちょこちょこ異なっているかもしれませんが無視してください。)
error[E0597]: `path` does not live long enough --> src\main.rs:31:17 | 30 | let exe_pash: &Path = match std::env::current_exe() { | _________________________- 31 | | Ok(path) => path.as_path(), | | ^^^^^^^^^^^^^- | | | | | | | `path` dropped here while still borrowed | | borrowed value does not live long enough 32 | | Err(_e) => Path::new("./"), 33 | | }; | |___- borrow later used here For more information about this error, try `rustc --explain E0597`.
こちらの問題を回避する方法を教えていただきたいです。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。