Expand description
A guard for a state value.
See Manager::manage
for usage examples.
Implementations§
source§impl<'r, T: Send + Sync + 'static> State<'r, T>
impl<'r, T: Send + Sync + 'static> State<'r, T>
sourcepub fn inner(&self) -> &'r T
pub fn inner(&self) -> &'r T
Retrieve a borrow to the underlying value with a lifetime of 'r
.
Using this method is typically unnecessary as State
implements
std::ops::Deref
with a std::ops::Deref::Target
of T
.
Examples found in repository?
src/lib.rs (line 764)
763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782
fn env(&self) -> Env {
self.state::<Env>().inner().clone()
}
/// Gets the scope for the filesystem APIs.
fn fs_scope(&self) -> FsScope {
self.state::<Scopes>().inner().fs.clone()
}
/// Gets the scope for the asset protocol.
#[cfg(protocol_asset)]
fn asset_protocol_scope(&self) -> FsScope {
self.state::<Scopes>().inner().asset_protocol.clone()
}
/// Gets the scope for the shell execute APIs.
#[cfg(shell_scope)]
fn shell_scope(&self) -> ShellScope {
self.state::<Scopes>().inner().shell.clone()
}
More examples
src/endpoints/path.rs (line 54)
46 47 48 49 50 51 52 53 54 55 56 57 58 59
fn resolve_path<R: Runtime>(
context: InvokeContext<R>,
path: String,
directory: Option<BaseDirectory>,
) -> super::Result<PathBuf> {
crate::api::path::resolve_path(
&context.config,
&context.package_info,
context.window.state::<Env>().inner(),
path,
directory,
)
.map_err(Into::into)
}
src/endpoints/file_system.rs (line 374)
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391
fn resolve_path<R: Runtime>(
config: &Config,
package_info: &PackageInfo,
window: &Window<R>,
path: SafePathBuf,
dir: Option<BaseDirectory>,
) -> super::Result<SafePathBuf> {
let env = window.state::<Env>().inner();
match crate::api::path::resolve_path(config, package_info, env, &path, dir) {
Ok(path) => {
if window.state::<Scopes>().fs.is_allowed(&path) {
Ok(
// safety: the path is resolved by Tauri so it is safe
unsafe { SafePathBuf::new_unchecked(path) },
)
} else {
Err(anyhow::anyhow!(
crate::Error::PathNotAllowed(path).to_string()
))
}
}
Err(e) => super::Result::<SafePathBuf>::Err(e.into())
.with_context(|| format!("path: {}, base dir: {:?}", path.display(), dir)),
}
}
Trait Implementations§
source§impl<'r, 'de: 'r, T: Send + Sync + 'static, R: Runtime> CommandArg<'de, R> for State<'r, T>
impl<'r, 'de: 'r, T: Send + Sync + 'static, R: Runtime> CommandArg<'de, R> for State<'r, T>
source§fn from_command(command: CommandItem<'de, R>) -> Result<Self, InvokeError>
fn from_command(command: CommandItem<'de, R>) -> Result<Self, InvokeError>
Grabs the State
from the CommandItem
. This will never fail.