pub struct PermissionsContainer(pub Arc<Mutex<Permissions>>);
Expand description

Wrapper struct for Permissions that can be shared across threads.

We need a way to have internal mutability for permissions as they might get passed to a future that will prompt the user for permission (and in such case might need to be mutated). Also for the Web Worker API we need a way to send permissions to a new thread.

Tuple Fields§

§0: Arc<Mutex<Permissions>>

Implementations§

source§

impl PermissionsContainer

source

pub fn new(perms: Permissions) -> Self

source

pub fn allow_all() -> Self

Examples found in repository?
examples/extension_with_ops/main.rs (line 28)
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
async fn main() -> Result<(), AnyError> {
  let js_path = Path::new(env!("CARGO_MANIFEST_DIR"))
    .join("examples/extension_with_ops/main.js");
  let main_module = ModuleSpecifier::from_file_path(js_path).unwrap();
  let mut worker = MainWorker::bootstrap_from_options(
    main_module.clone(),
    PermissionsContainer::allow_all(),
    WorkerOptions {
      module_loader: Rc::new(FsModuleLoader),
      extensions: vec![hello_runtime::init_ops()],
      ..Default::default()
    },
  );
  worker.execute_main_module(&main_module).await?;
  worker.run_event_loop(false).await?;
  Ok(())
}
More examples
Hide additional examples
examples/extension_with_esm/main.rs (line 26)
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
async fn main() -> Result<(), AnyError> {
  let js_path = Path::new(env!("CARGO_MANIFEST_DIR"))
    .join("examples/extension_with_esm/main.js");
  let main_module = ModuleSpecifier::from_file_path(js_path).unwrap();
  let mut worker = MainWorker::bootstrap_from_options(
    main_module.clone(),
    PermissionsContainer::allow_all(),
    WorkerOptions {
      module_loader: Rc::new(FsModuleLoader),
      extensions: vec![hello_runtime::init_ops_and_esm()],
      ..Default::default()
    },
  );
  worker.execute_main_module(&main_module).await?;
  worker.run_event_loop(false).await?;
  Ok(())
}
source

pub fn check_specifier( &self, specifier: &ModuleSpecifier ) -> Result<(), AnyError>

source

pub fn check_read( &mut self, path: &Path, api_name: &str ) -> Result<(), AnyError>

source

pub fn check_read_blind( &mut self, path: &Path, display: &str, api_name: &str ) -> Result<(), AnyError>

source

pub fn check_read_all(&mut self, api_name: &str) -> Result<(), AnyError>

source

pub fn check_write( &mut self, path: &Path, api_name: &str ) -> Result<(), AnyError>

source

pub fn check_write_all(&mut self, api_name: &str) -> Result<(), AnyError>

source

pub fn check_write_blind( &mut self, path: &Path, display: &str, api_name: &str ) -> Result<(), AnyError>

source

pub fn check_run(&mut self, cmd: &str, api_name: &str) -> Result<(), AnyError>

source

pub fn check_run_all(&mut self, api_name: &str) -> Result<(), AnyError>

source

pub fn check_sys(&mut self, kind: &str, api_name: &str) -> Result<(), AnyError>

source

pub fn check_env(&mut self, var: &str) -> Result<(), AnyError>

source

pub fn check_env_all(&mut self) -> Result<(), AnyError>

Trait Implementations§

source§

impl Clone for PermissionsContainer

source§

fn clone(&self) -> PermissionsContainer

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for PermissionsContainer

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl FetchPermissions for PermissionsContainer

source§

fn check_net_url(&mut self, url: &Url, api_name: &str) -> Result<(), AnyError>

source§

fn check_read(&mut self, path: &Path, api_name: &str) -> Result<(), AnyError>

source§

impl FfiPermissions for PermissionsContainer

source§

fn check_partial(&mut self, path: Option<&Path>) -> Result<(), AnyError>

source§

impl FsPermissions for PermissionsContainer

source§

fn check_read(&mut self, path: &Path, api_name: &str) -> Result<(), AnyError>

source§

fn check_read_blind( &mut self, path: &Path, display: &str, api_name: &str ) -> Result<(), AnyError>

source§

fn check_write(&mut self, path: &Path, api_name: &str) -> Result<(), AnyError>

source§

fn check_write_partial( &mut self, path: &Path, api_name: &str ) -> Result<(), AnyError>

source§

fn check_write_blind( &mut self, p: &Path, display: &str, api_name: &str ) -> Result<(), AnyError>

source§

fn check_read_all(&mut self, api_name: &str) -> Result<(), AnyError>

source§

fn check_write_all(&mut self, api_name: &str) -> Result<(), AnyError>

source§

fn check( &mut self, open_options: &OpenOptions, path: &Path, api_name: &str ) -> Result<(), Error>

source§

impl NapiPermissions for PermissionsContainer

source§

fn check(&mut self, path: Option<&Path>) -> Result<(), AnyError>

source§

impl NetPermissions for PermissionsContainer

source§

fn check_net<T: AsRef<str>>( &mut self, host: &(T, Option<u16>), api_name: &str ) -> Result<(), AnyError>

source§

fn check_read(&mut self, path: &Path, api_name: &str) -> Result<(), AnyError>

source§

fn check_write(&mut self, path: &Path, api_name: &str) -> Result<(), AnyError>

source§

impl NodePermissions for PermissionsContainer

source§

fn check_net_url(&mut self, url: &Url, api_name: &str) -> Result<(), AnyError>

source§

fn check_read(&self, path: &Path) -> Result<(), AnyError>

source§

fn check_sys(&self, kind: &str, api_name: &str) -> Result<(), AnyError>

source§

impl RemoteDbHandlerPermissions for PermissionsContainer

source§

fn check_env(&mut self, var: &str) -> Result<(), AnyError>

source§

fn check_net_url(&mut self, url: &Url, api_name: &str) -> Result<(), AnyError>

source§

impl SqliteDbHandlerPermissions for PermissionsContainer

source§

fn check_read(&mut self, p: &Path, api_name: &str) -> Result<(), AnyError>

source§

fn check_write(&mut self, p: &Path, api_name: &str) -> Result<(), AnyError>

source§

impl TimersPermission for PermissionsContainer

source§

fn allow_hrtime(&mut self) -> bool

source§

impl WebSocketPermissions for PermissionsContainer

source§

fn check_net_url(&mut self, url: &Url, api_name: &str) -> Result<(), AnyError>

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32 ) -> TaggedParser<'a, Implicit, Self, E>

source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> DynClone for T
where T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

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

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
§

impl<T> Send for T
where T: ?Sized,

§

impl<T> Sync for T
where T: ?Sized,