前提
tauriを使ってフロントエンドがjs(vue.js)、バックエンド(Rust)のデスクトップアプリを作成してます。
Rustについてはまったくの初学者で初歩の初歩でつまずいてます。
実現したいこと
exeファイルのフルパスをstd::path::Pathの型で取得したいです。
最終的には「[exeファイルのディレクトリ]/tasklist/tasklist.csv」のフルパスを上記のexeファイルのフルパスから生成したいと思ってます。
発生している問題・エラーメッセージ
こちらのコードを実行しようとすると
Rust
fn read_task_list() { //get task list filepath let exe_pash: &Path = match std::env::current_exe() { Ok(path) => path.as_path(), Err(_e) => Path::new("./"), };
このようなエラーが出ます。
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`.
こちらの問題を回避する方法を教えていただきたいです。
まだ回答がついていません
会員登録して回答してみよう