Struct deno_runtime::permissions::PermissionsContainer
source · 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
impl PermissionsContainer
pub fn new(perms: Permissions) -> Self
sourcepub fn allow_all() -> Self
pub fn allow_all() -> Self
Examples found in repository?
examples/hello_runtime.rs (line 64)
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
async fn main() -> Result<(), AnyError> {
let module_loader = Rc::new(FsModuleLoader);
let create_web_worker_cb = Arc::new(|_| {
todo!("Web workers are not supported in the example");
});
let web_worker_event_cb = Arc::new(|_| {
todo!("Web workers are not supported in the example");
});
let options = WorkerOptions {
bootstrap: BootstrapOptions::default(),
extensions: vec![],
startup_snapshot: None,
unsafely_ignore_certificate_errors: None,
root_cert_store: None,
seed: None,
source_map_getter: None,
format_js_error_fn: None,
web_worker_preload_module_cb: web_worker_event_cb.clone(),
web_worker_pre_execute_module_cb: web_worker_event_cb,
create_web_worker_cb,
maybe_inspector_server: None,
should_break_on_first_statement: false,
should_wait_for_inspector_session: false,
module_loader,
node_fs: None,
npm_resolver: None,
get_error_class_fn: Some(&get_error_class_name),
cache_storage_dir: None,
origin_storage_dir: None,
blob_store: BlobStore::default(),
broadcast_channel: InMemoryBroadcastChannel::default(),
shared_array_buffer_store: None,
compiled_wasm_module_store: None,
stdio: Default::default(),
};
let js_path =
Path::new(env!("CARGO_MANIFEST_DIR")).join("examples/hello_runtime.js");
let main_module = deno_core::resolve_path(
&js_path.to_string_lossy(),
&std::env::current_dir().context("Unable to get CWD")?,
)?;
let permissions = PermissionsContainer::allow_all();
let mut worker = MainWorker::bootstrap_from_options(
main_module.clone(),
permissions,
options,
);
worker.execute_main_module(&main_module).await?;
worker.run_event_loop(false).await?;
Ok(())
}
pub fn check_specifier( &self, specifier: &ModuleSpecifier ) -> Result<(), AnyError>
pub fn check_read( &mut self, path: &Path, api_name: &str ) -> Result<(), AnyError>
pub fn check_read_blind( &mut self, path: &Path, display: &str, api_name: &str ) -> Result<(), AnyError>
pub fn check_read_all(&mut self, api_name: &str) -> Result<(), AnyError>
pub fn check_write( &mut self, path: &Path, api_name: &str ) -> Result<(), AnyError>
pub fn check_write_all(&mut self, api_name: &str) -> Result<(), AnyError>
pub fn check_write_blind( &mut self, path: &Path, display: &str, api_name: &str ) -> Result<(), AnyError>
pub fn check_run(&mut self, cmd: &str, api_name: &str) -> Result<(), AnyError>
pub fn check_run_all(&mut self, api_name: &str) -> Result<(), AnyError>
pub fn check_sys(&mut self, kind: &str, api_name: &str) -> Result<(), AnyError>
pub fn check_env(&mut self, var: &str) -> Result<(), AnyError>
pub fn check_env_all(&mut self) -> Result<(), AnyError>
Trait Implementations§
source§impl Clone for PermissionsContainer
impl Clone for PermissionsContainer
source§fn clone(&self) -> PermissionsContainer
fn clone(&self) -> PermissionsContainer
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for PermissionsContainer
impl Debug for PermissionsContainer
source§impl FsPermissions for PermissionsContainer
impl FsPermissions for PermissionsContainer
fn check_read(&mut self, path: &Path, api_name: &str) -> Result<(), AnyError>
fn check_read_blind( &mut self, path: &Path, display: &str, api_name: &str ) -> Result<(), AnyError>
fn check_write(&mut self, path: &Path, api_name: &str) -> Result<(), AnyError>
fn check_write_blind( &mut self, p: &Path, display: &str, api_name: &str ) -> Result<(), AnyError>
fn check_read_all(&mut self, api_name: &str) -> Result<(), AnyError>
fn check_write_all(&mut self, api_name: &str) -> Result<(), AnyError>
fn check( &mut self, open_options: &OpenOptions, path: &Path, api_name: &str ) -> Result<(), Error>
source§impl TimersPermission for PermissionsContainer
impl TimersPermission for PermissionsContainer
fn allow_hrtime(&mut self) -> bool
fn check_unstable(&self, state: &OpState, api_name: &'static str)
Auto Trait Implementations§
impl !RefUnwindSafe for PermissionsContainer
impl Send for PermissionsContainer
impl Sync for PermissionsContainer
impl Unpin for PermissionsContainer
impl !UnwindSafe for PermissionsContainer
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere T: 'a,
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more