Skip to main content

FsExt

Trait FsExt 

Source
pub trait FsExt<R: Runtime> {
    // Required methods
    fn fs_scope(&self) -> Scope;
    fn try_fs_scope(&self) -> Option<Scope>;
    fn fs(&self) -> &Fs<R>;
}
Expand description

Extension trait implemented by every Manager (the app handle, windows, webviews, …) to access the file system plugin APIs.

§Examples

use std::path::Path;
use tauri::Runtime;
use tauri_plugin_fs::FsExt;

fn setup<R: Runtime>(app: &tauri::App<R>) -> Result<(), Box<dyn std::error::Error>> {
    // allow the app to access a directory that is not part of the static scope
    app.fs_scope().allow_directory(Path::new("/path/to/directory"), true)?;

    let contents = app.fs().read_to_string(Path::new("/path/to/directory/file.txt"))?;
    println!("{contents}");

    Ok(())
}

Required Methods§

Source

fn fs_scope(&self) -> Scope

Returns the file system scope, which can be used to dynamically allow or deny paths at runtime.

§Panics

Panics if the plugin is not registered in the app. Use FsExt::try_fs_scope if the plugin might not be registered.

Source

fn try_fs_scope(&self) -> Option<Scope>

Returns the file system scope, or None if the plugin is not registered in the app.

Source

fn fs(&self) -> &Fs<R>

Cross platform file system APIs that also support manipulating Android files.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<R: Runtime, T: Manager<R>> FsExt<R> for T