Skip to main content

System

Struct System 

Source
#[non_exhaustive]
pub struct System {
Show 14 fields pub access: Arc<Access>, pub data_dir: Option<PathBuf>, pub asset_base: Option<AssetBase>, pub paths: TrustedPaths, pub quotas: Quotas, pub locals: Locals, pub exit: Option<Rc<dyn Fn(i32)>>, pub websocket: Option<Arc<dyn WebSocketTransport>>, pub filesystem: Option<Arc<dyn FileSystem>>, pub os: Os, pub clipboard_images: Option<bool>, pub refuse_connections: Option<RefuseConnections>, pub updater: Option<Arc<dyn UpdaterHost>>, pub base_url: Option<Arc<str>>, /* private fields */
}
Expand description

The VM a call comes from, as the host configured it: what the app may do and where its files are. A parameter sys: System of a module function or a class’s member is not one JS passes: the call fills it in (an async one when it is made, as its arguments are converted). A host that configured nothing gives one that grants nothing.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§access: Arc<Access>

The capabilities: the app’s declaration and the host’s grant.

§data_dir: Option<PathBuf>

The app’s own data directory (${dataDir}), when the host has one.

§asset_base: Option<AssetBase>

Where the app’s bundled (asset:/…) files are on disk, when the host has them in directories it can name: a packaged desktop app’s own, beside the running runner. process.run of an asset:/… program resolves it through this; None on the web (the dev server serves the files over HTTP) and on iOS and Android, where a bundled file cannot run.

§paths: TrustedPaths

The host’s anchors of ${pluginDir} and ${homeDir}.

§quotas: Quotas

The VM’s counts of limited resources.

§locals: Locals

The VM’s own state of the runtime’s modules (process’s children).

§exit: Option<Rc<dyn Fn(i32)>>

What the host does when the app asks to exit (process.exit); None: it installed nothing.

§websocket: Option<Arc<dyn WebSocketTransport>>

The host WebSocket transport, when the platform supplies one.

§filesystem: Option<Arc<dyn FileSystem>>

The host virtual filesystem, confined to this app’s data directory.

§os: Os

The operating system the app runs on, as the host says.

§clipboard_images: Option<bool>

Whether the platform puts images on the clipboard and reads them back; None: as NSH’s own backend on Self::os (crate::platform::Environment::clipboard_images).

§refuse_connections: Option<RefuseConnections>

Refuses the app’s connections (net sockets and WebSockets, both APIs) before they reach the network: a test’s, which reaches it only when the test asks (nsh test’s network: "live"). None: they connect. fetch goes through the host’s network instead.

§updater: Option<Arc<dyn UpdaterHost>>

What nsh/updater runs on; None: the app does not update.

§base_url: Option<Arc<str>>

What // media sources resolve against, the page’s URL on the web (Access::media_url); None: such a source names no URL.

Implementations§

Source§

impl System

Source

pub fn new( access: Arc<Access>, data_dir: Option<PathBuf>, paths: TrustedPaths, quotas: Quotas, ) -> Self

The VM’s capabilities and directories.

Source

pub fn check_connection(&self, target: &str) -> Result<(), JsError>

Whether the app may connect to target (a WebSocket’s URL, a socket’s host:port) as far as the host is concerned: the error System::refuse_connections gives, when the host set one. The app’s capabilities are checked apart.

Source

pub fn readable_file(&self, path: &str) -> Result<PathBuf, JsError>

The real path of the local file path names (absolute, or a placeholder path such as ${dataDir}/report.pdf), checked as fs/promises reads it: within the roots capabilities.fs.read grants (the app’s declaration and the host’s grant), or a file the user pasted or dropped, its links resolved and still inside the root that grants it. For a module that hands a file the app names to the system or to another app (a share sheet, a print job, an upload), so the file is checked as the app’s own reads are.

Rejects as fs/promises would: ERR_ACCESS_DENIED for a path no grant covers or a link leading out of its root, ENOENT for one that does not exist, EISDIR for a folder (EINVAL for a FIFO or device), ERR_FEATURE_UNAVAILABLE_ON_PLATFORM where the app’s files are not native files (the web) or the platform has no native filesystem.

Source

pub fn with_refuse_connections(self, refuse: Option<RefuseConnections>) -> Self

Refuses the app’s connections with what refuse gives (System::refuse_connections).

Source

pub fn with_websocket( self, websocket: Option<Arc<dyn WebSocketTransport>>, ) -> Self

Uses the host WebSocket transport instead of the native stack.

Source

pub fn with_asset_base(self, base: Option<AssetBase>) -> Self

Sets where the app’s bundled (asset:/…) files are on disk, when the host has them in directories it can name (process.run of an asset:/… program resolves through this).

Source

pub fn with_updater(self, updater: Option<Arc<dyn UpdaterHost>>) -> Self

Uses the host virtual filesystem. Sets what nsh/updater runs on.

Source

pub fn with_base_url(self, base_url: Option<Arc<str>>) -> Self

What // media sources resolve against (System::base_url).

Source

pub fn with_filesystem(self, filesystem: Option<Arc<dyn FileSystem>>) -> Self

The host virtual filesystem the VM’s storage runs on.

Source

pub fn with_os(self, os: Os) -> Self

The operating system the app runs on.

Source

pub fn with_clipboard_images(self, clipboard_images: Option<bool>) -> Self

Whether the platform puts images on the clipboard; None: as NSH’s own backend on the OS (crate::platform::Environment::clipboard_images).

Source

pub fn with_locals(self, locals: Locals) -> Self

The VM’s state of the runtime modules, kept with it.

Source

pub fn with_exit(self, exit: Option<Rc<dyn Fn(i32)>>) -> Self

What the host does with an exit request.

Trait Implementations§

Source§

impl Clone for System

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for System

Source§

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

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

impl Default for System

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for System

§

impl !Send for System

§

impl !Sync for System

§

impl !UnwindSafe for System

§

impl Forget for System

§

impl Freeze for System
where *const ArcInner<Access> is !null: Freeze, PhantomData<ArcInner<Access>>: Freeze, *const u8 is !null: Freeze, PhantomData<u8>: Freeze, PhantomData<PathBuf>: Freeze, *const RcInner<RefCell<HashMap<&'static str, usize, FxBuildHasher>>> is !null: Freeze, PhantomData<RcInner<RefCell<HashMap<&'static str, usize, FxBuildHasher>>>>: Freeze, *const RcInner<RefCell<Vec<(TypeId, Rc<dyn Any>, fn(&(dyn Any + 'static)))>>> is !null: Freeze, PhantomData<RcInner<RefCell<Vec<(TypeId, Rc<dyn Any>, fn(&(dyn Any + 'static)))>>>>: Freeze, *const RcInner<dyn Fn(i32)> is !null: Freeze, PhantomData<RcInner<dyn Fn(i32)>>: Freeze, *const ArcInner<dyn WebSocketTransport> is !null: Freeze, PhantomData<ArcInner<dyn WebSocketTransport>>: Freeze, *const ArcInner<dyn FileSystem> is !null: Freeze, PhantomData<ArcInner<dyn FileSystem>>: Freeze, *const ArcInner<dyn Fn(&str) -> JsError + Sync + Send> is !null: Freeze, PhantomData<ArcInner<dyn Fn(&str) -> JsError + Sync + Send>>: Freeze, *const ArcInner<dyn UpdaterHost> is !null: Freeze, PhantomData<ArcInner<dyn UpdaterHost>>: Freeze, *const RcInner<RefCell<AppUrlState>> is !null: Freeze, PhantomData<RcInner<RefCell<AppUrlState>>>: Freeze, *const ArcInner<str> is !null: Freeze, PhantomData<ArcInner<str>>: Freeze,

§

impl Move for System

§

impl Unpin for System
where Arc<Access>: Unpin, *const u8 is !null: Unpin, Rc<RefCell<HashMap<&'static str, usize, FxBuildHasher>>>: Unpin, Rc<RefCell<Vec<(TypeId, Rc<dyn Any>, fn(&(dyn Any + 'static)))>>>: Unpin, Rc<dyn Fn(i32)>: Unpin, Arc<dyn WebSocketTransport>: Unpin, Arc<dyn FileSystem>: Unpin, Arc<dyn Fn(&str) -> JsError + Sync + Send>: Unpin, Arc<dyn UpdaterHost>: Unpin, Rc<RefCell<AppUrlState>>: Unpin, Arc<str>: Unpin,

§

impl UnsafeUnpin for System
where *const ArcInner<Access> is !null: UnsafeUnpin, PhantomData<ArcInner<Access>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, PhantomData<PathBuf>: UnsafeUnpin, *const RcInner<RefCell<HashMap<&'static str, usize, FxBuildHasher>>> is !null: UnsafeUnpin, PhantomData<RcInner<RefCell<HashMap<&'static str, usize, FxBuildHasher>>>>: UnsafeUnpin, *const RcInner<RefCell<Vec<(TypeId, Rc<dyn Any>, fn(&(dyn Any + 'static)))>>> is !null: UnsafeUnpin, PhantomData<RcInner<RefCell<Vec<(TypeId, Rc<dyn Any>, fn(&(dyn Any + 'static)))>>>>: UnsafeUnpin, *const RcInner<dyn Fn(i32)> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(i32)>>: UnsafeUnpin, *const ArcInner<dyn WebSocketTransport> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn WebSocketTransport>>: UnsafeUnpin, *const ArcInner<dyn FileSystem> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn FileSystem>>: UnsafeUnpin, *const ArcInner<dyn Fn(&str) -> JsError + Sync + Send> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn Fn(&str) -> JsError + Sync + Send>>: UnsafeUnpin, *const ArcInner<dyn UpdaterHost> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn UpdaterHost>>: UnsafeUnpin, *const RcInner<RefCell<AppUrlState>> is !null: UnsafeUnpin, PhantomData<RcInner<RefCell<AppUrlState>>>: UnsafeUnpin, *const ArcInner<str> is !null: UnsafeUnpin, PhantomData<ArcInner<str>>: UnsafeUnpin,

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
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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

Source§

type Output = T

Should always be Self
Source§

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

Source§

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>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.