27 lines
837 B
Rust
27 lines
837 B
Rust
//! Asset-Pfadauflösung: Distribution-Layout (assets/ neben der Binary)
|
|
//! oder Dev-Layout (assets/ im CWD, also Projektroot bei `cargo run`).
|
|
|
|
use std::path::PathBuf;
|
|
use std::sync::OnceLock;
|
|
|
|
static BASE: OnceLock<PathBuf> = OnceLock::new();
|
|
|
|
fn base() -> &'static PathBuf {
|
|
BASE.get_or_init(|| {
|
|
if let Ok(exe) = std::env::current_exe() {
|
|
if let Some(dir) = exe.parent() {
|
|
if dir.join("assets").exists() {
|
|
return dir.to_path_buf();
|
|
}
|
|
}
|
|
}
|
|
std::env::current_dir().unwrap_or_else(|_| PathBuf::from("."))
|
|
})
|
|
}
|
|
|
|
/// Wandelt einen relativen Pfad wie `"assets/signals.toml"` in einen
|
|
/// absoluten Pfad relativ zum Asset-Basisverzeichnis um.
|
|
pub fn path(rel: &str) -> String {
|
|
base().join(rel).to_string_lossy().into_owned()
|
|
}
|