Function zng_env::res

source ·
pub fn res(relative_path: impl AsRef<Path>) -> PathBuf
Expand description

Gets a path relative to the package resources.

  • The res dir can be set by init_res before any env dir is used.
  • In Android returns android_internal("res"), assumes the package assets are extracted to this directory.
  • In Linux, macOS and Windows if a file bin/current_exe_name.res-dir is found the first non-empty and non-comment (#) line defines the res path.
  • In cfg(debug_assertions) builds returns res.
  • In Wasm returns ./res, as in the relative URL.
  • In macOS returns bin("../Resources"), assumes the package is deployed using a desktop .app folder.
  • In all other Unix systems returns bin("../share/current_exe_name"), assumes the package is deployed using a Debian package.
  • In Windows returns bin("../res"). Note that there is no Windows standard, make sure to install the project using this structure.

§Built Resources

In cfg(any(debug_assertions, feature="built_res")) builds if the target/res/{relative_path} path exists it is returned instead. This is useful during development when the app depends on res that are generated locally and not included in version control.

Note that the built resources must be packaged with the other res at the same relative location, so that release builds can find them.

§Android

Unfortunately Android does not provide file system access to the bundled resources, you must use the ndk::asset::AssetManager to request files that are decompressed on demand from the APK file. We recommend extracting all cross-platform assets once on startup to avoid having to implement special Android handling for each resource usage. See android_install_res for more details.