Struct tauri::State

source ·
pub struct State<'r, T: Send + Sync + 'static>(_);
Expand description

A guard for a state value.

See Manager::manage for usage examples.

Implementations§

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
Hide additional 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§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more

Grabs the State from the CommandItem. This will never fail.

Formats the value using the given formatter. Read more
The resulting type after dereferencing.
Dereferences the value.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more