pub struct PathResolver<R: Runtime>(/* private fields */);Expand description
The path resolver is a helper class for general and application-specific path APIs.
Implementations§
Source§impl<R: Runtime> PathResolver<R>
impl<R: Runtime> PathResolver<R>
Sourcepub fn file_name(&self, path: &str) -> Option<String>
pub fn file_name(&self, path: &str) -> Option<String>
Returns the final component of the Path, if there is one.
If the path is a normal file, this is the file name. If it’s the path of a directory, this is the directory name.
Returns None if the path terminates in ...
On Android this also supports checking the file name of content URIs, such as the values returned by the dialog plugin.
If you are dealing with plain file system paths or not worried about Android content URIs, prefer Path::file_name.
Sourcepub fn audio_dir(&self) -> Result<PathBuf>
pub fn audio_dir(&self) -> Result<PathBuf>
Returns the path to the user’s audio directory.
§Platform-specific
- Linux: Resolves to
xdg-user-dirs’XDG_MUSIC_DIR. - macOS: Resolves to
$HOME/Music. - Windows: Resolves to
{FOLDERID_Music}.
Sourcepub fn cache_dir(&self) -> Result<PathBuf>
pub fn cache_dir(&self) -> Result<PathBuf>
Returns the path to the user’s cache directory.
§Platform-specific
- Linux: Resolves to
$XDG_CACHE_HOMEor$HOME/.cache. - macOS: Resolves to
$HOME/Library/Caches. - Windows: Resolves to
{FOLDERID_LocalAppData}.
Sourcepub fn config_dir(&self) -> Result<PathBuf>
pub fn config_dir(&self) -> Result<PathBuf>
Returns the path to the user’s config directory.
§Platform-specific
- Linux: Resolves to
$XDG_CONFIG_HOMEor$HOME/.config. - macOS: Resolves to
$HOME/Library/Application Support. - Windows: Resolves to
{FOLDERID_RoamingAppData}.
Sourcepub fn data_dir(&self) -> Result<PathBuf>
pub fn data_dir(&self) -> Result<PathBuf>
Returns the path to the user’s data directory.
§Platform-specific
- Linux: Resolves to
$XDG_DATA_HOMEor$HOME/.local/share. - macOS: Resolves to
$HOME/Library/Application Support. - Windows: Resolves to
{FOLDERID_RoamingAppData}.
Sourcepub fn local_data_dir(&self) -> Result<PathBuf>
pub fn local_data_dir(&self) -> Result<PathBuf>
Returns the path to the user’s local data directory.
§Platform-specific
- Linux: Resolves to
$XDG_DATA_HOMEor$HOME/.local/share. - macOS: Resolves to
$HOME/Library/Application Support. - Windows: Resolves to
{FOLDERID_LocalAppData}.
Sourcepub fn desktop_dir(&self) -> Result<PathBuf>
pub fn desktop_dir(&self) -> Result<PathBuf>
Returns the path to the user’s desktop directory.
§Platform-specific
- Linux: Resolves to
xdg-user-dirs’XDG_DESKTOP_DIR. - macOS: Resolves to
$HOME/Desktop. - Windows: Resolves to
{FOLDERID_Desktop}.
Sourcepub fn document_dir(&self) -> Result<PathBuf>
pub fn document_dir(&self) -> Result<PathBuf>
Returns the path to the user’s document directory.
§Platform-specific
- Linux: Resolves to
xdg-user-dirs’XDG_DOCUMENTS_DIR. - macOS: Resolves to
$HOME/Documents. - Windows: Resolves to
{FOLDERID_Documents}.
Sourcepub fn download_dir(&self) -> Result<PathBuf>
pub fn download_dir(&self) -> Result<PathBuf>
Returns the path to the user’s download directory.
§Platform-specific
- Linux: Resolves to
xdg-user-dirs’XDG_DOWNLOAD_DIR. - macOS: Resolves to
$HOME/Downloads. - Windows: Resolves to
{FOLDERID_Downloads}.
Sourcepub fn executable_dir(&self) -> Result<PathBuf>
pub fn executable_dir(&self) -> Result<PathBuf>
Returns the path to the user’s executable directory.
§Platform-specific
- Linux: Resolves to
$XDG_BIN_HOME/../binor$XDG_DATA_HOME/../binor$HOME/.local/bin. - macOS: Not supported.
- Windows: Not supported.
Sourcepub fn font_dir(&self) -> Result<PathBuf>
pub fn font_dir(&self) -> Result<PathBuf>
Returns the path to the user’s font directory.
§Platform-specific
- Linux: Resolves to
$XDG_DATA_HOME/fontsor$HOME/.local/share/fonts. - macOS: Resolves to
$HOME/Library/Fonts. - Windows: Not supported.
Sourcepub fn home_dir(&self) -> Result<PathBuf>
pub fn home_dir(&self) -> Result<PathBuf>
Returns the path to the user’s home directory.
§Platform-specific
- Linux: Resolves to
$HOME. - macOS: Resolves to
$HOME. - Windows: Resolves to
{FOLDERID_Profile}. - iOS: Cannot be written to directly, use one of the app paths instead.
Sourcepub fn picture_dir(&self) -> Result<PathBuf>
pub fn picture_dir(&self) -> Result<PathBuf>
Returns the path to the user’s picture directory.
§Platform-specific
- Linux: Resolves to
xdg-user-dirs’XDG_PICTURES_DIR. - macOS: Resolves to
$HOME/Pictures. - Windows: Resolves to
{FOLDERID_Pictures}.
Sourcepub fn public_dir(&self) -> Result<PathBuf>
pub fn public_dir(&self) -> Result<PathBuf>
Returns the path to the user’s public directory.
§Platform-specific
- Linux: Resolves to
xdg-user-dirs’XDG_PUBLICSHARE_DIR. - macOS: Resolves to
$HOME/Public. - Windows: Resolves to
{FOLDERID_Public}.
Sourcepub fn runtime_dir(&self) -> Result<PathBuf>
pub fn runtime_dir(&self) -> Result<PathBuf>
Returns the path to the user’s runtime directory.
§Platform-specific
- Linux: Resolves to
$XDG_RUNTIME_DIR. - macOS: Not supported.
- Windows: Not supported.
Sourcepub fn template_dir(&self) -> Result<PathBuf>
pub fn template_dir(&self) -> Result<PathBuf>
Returns the path to the user’s template directory.
§Platform-specific
- Linux: Resolves to
xdg-user-dirs’XDG_TEMPLATES_DIR. - macOS: Not supported.
- Windows: Resolves to
{FOLDERID_Templates}.
Sourcepub fn video_dir(&self) -> Result<PathBuf>
pub fn video_dir(&self) -> Result<PathBuf>
Returns the path to the user’s video dir
§Platform-specific
- Linux: Resolves to
xdg-user-dirs’XDG_VIDEOS_DIR. - macOS: Resolves to
$HOME/Movies. - Windows: Resolves to
{FOLDERID_Videos}.
Sourcepub fn resource_dir(&self) -> Result<PathBuf>
pub fn resource_dir(&self) -> Result<PathBuf>
Returns the path to the resource directory of this app.
§Platform-specific
Although we provide the exact path where this function resolves to, this is not a contract and things might change in the future
- Windows: Resolves to the directory that contains the main executable.
- Linux: When running in an AppImage, the
APPDIRvariable will be set to the mounted location of the app, and the resource dir will be${APPDIR}/usr/lib/${exe_name}. If not running in an AppImage, the path is/usr/lib/${exe_name}. When running the app fromsrc-tauri/target/(debug|release)/, the path is${exe_dir}/../lib/${exe_name}. - macOS: Resolves to
${exe_dir}/../Resources(inside .app). - iOS: Resolves to
${exe_dir}/assets. - Android: Currently the resources are stored in the APK as assets so it’s not a normal file system path,
we return a special URI prefix
asset://localhost/here that can be used with the file system plugin, with that, you can read the files throughFsExt::fslike this:app.fs().read_to_string(app.path().resource_dir().unwrap().join("resource"));
Sourcepub fn app_config_dir(&self) -> Result<PathBuf>
pub fn app_config_dir(&self) -> Result<PathBuf>
Returns the path to the suggested directory for your app’s config files.
Resolves to config_dir/${bundle_identifier}.
Sourcepub fn app_data_dir(&self) -> Result<PathBuf>
pub fn app_data_dir(&self) -> Result<PathBuf>
Returns the path to the suggested directory for your app’s data files.
Resolves to data_dir/${bundle_identifier}.
Sourcepub fn app_local_data_dir(&self) -> Result<PathBuf>
pub fn app_local_data_dir(&self) -> Result<PathBuf>
Returns the path to the suggested directory for your app’s local data files.
Resolves to local_data_dir/${bundle_identifier}.
Sourcepub fn app_cache_dir(&self) -> Result<PathBuf>
pub fn app_cache_dir(&self) -> Result<PathBuf>
Returns the path to the suggested directory for your app’s cache files.
Resolves to cache_dir/${bundle_identifier}.
Sourcepub fn app_log_dir(&self) -> Result<PathBuf>
pub fn app_log_dir(&self) -> Result<PathBuf>
Returns the path to the suggested directory for your app’s log files.
§Platform-specific
- Linux: Resolves to
local_data_dir/${bundle_identifier}/logs. - macOS: Resolves to
home_dir/Library/Logs/${bundle_identifier} - Windows: Resolves to
local_data_dir/${bundle_identifier}/logs.
Sourcepub fn temp_dir(&self) -> Result<PathBuf>
pub fn temp_dir(&self) -> Result<PathBuf>
A temporary directory. Resolves to std::env::temp_dir.
Source§impl<R: Runtime> PathResolver<R>
impl<R: Runtime> PathResolver<R>
Sourcepub fn resolve<P: AsRef<Path>>(
&self,
path: P,
base_directory: BaseDirectory,
) -> Result<PathBuf>
pub fn resolve<P: AsRef<Path>>( &self, path: P, base_directory: BaseDirectory, ) -> Result<PathBuf>
Resolves the path with the base directory.
§Examples
use tauri::{path::BaseDirectory, Manager};
tauri::Builder::default()
.setup(|app| {
let path = app.path().resolve("path/to/something", BaseDirectory::Config)?;
assert_eq!(path.to_str().unwrap(), "/home/${whoami}/.config/path/to/something");
Ok(())
});Sourcepub fn parse<P: AsRef<Path>>(&self, path: P) -> Result<PathBuf>
pub fn parse<P: AsRef<Path>>(&self, path: P) -> Result<PathBuf>
Parse the given path, resolving a BaseDirectory variable if the path starts with one.
§Examples
use tauri::Manager;
tauri::Builder::default()
.setup(|app| {
let path = app.path().parse("$HOME/.bashrc")?;
assert_eq!(path.to_str().unwrap(), "/home/${whoami}/.bashrc");
Ok(())
});