#[non_exhaustive]pub struct Capabilities {Show 19 fields
pub process: ProcessGrants,
pub fs: FileGrants,
pub network: NetworkGrants,
pub webview: Option<Vec<HostPattern>>,
pub webview_input: bool,
pub webview_runtime_origin: bool,
pub webview_media: Vec<WebMedia>,
pub status_bar: bool,
pub clipboard: bool,
pub picker: bool,
pub share: bool,
pub speech: bool,
pub notifications: bool,
pub audio: bool,
pub application: bool,
pub home_dir: bool,
pub host: Vec<String>,
pub open_url: Option<OpenUrlGrant>,
pub windows: Option<WindowsGrant>,
}Expand description
What an app may do (one declaration, or one grant).
Start with Self::default and set the fields to grant; new capabilities
default to denied.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.process: ProcessGrantsExplicit native subprocess grants.
fs: FileGrantsExplicit native filesystem grants.
network: NetworkGrantsfetch, remote images and video.
webview: Option<Vec<HostPattern>>The hosts web views may show; None: no web views.
webview_input: boolWeb views may take trusted input (sendInput, webview.input):
never without a declaration (Capabilities::all leaves it off).
webview_runtime_origin: boolA web view’s allowOrigin adds one origin to the hosts it may show
(webview.runtimeOrigin): never without a declaration
(Capabilities::all leaves it off).
webview_media: Vec<WebMedia>What web views’ pages may capture (webview.media): never without a
declaration (Capabilities::all leaves it empty).
status_bar: boolThe app may set the status bar.
clipboard: boolThe app may read and write the system clipboard (nsh/clipboard).
picker: boolThe app may show the system’s picker (nsh/picker): the files the
user picks in it reach the app.
The app may show the system’s share sheet (Share of nsh-extra): the
text, links and files it shares leave the app where the user sends
them.
speech: boolThe app may recognize the user’s speech (Speech of nsh-extra): the
microphone listens while a session runs, and the transcript reaches
the app.
notifications: boolThe app may show notifications and set its badge (Notifications of
nsh). The user’s permission is the system’s, on top of this.
audio: boolThe app may play sound (Sound and AudioPlayer of nsh).
application: boolThe app may act on the application as a whole: the main window, the
application menu, the tray, global shortcuts, quitting, restarting
and launching at login (nsh/desktop), and the app’s page in the
system’s settings (nsh/mobile’s AppSettings).
home_dir: boolos.homedir() may tell the user’s home directory.
host: Vec<String>The functions of the embedding app nsh/host may call: names, or
prefixes ending in * ("*": all); empty: none, also for apps
without a declaration (Capabilities::all).
open_url: Option<OpenUrlGrant>The URLs the app may open outside it (openUrl of nsh/device);
None: none.
windows: Option<WindowsGrant>The windows the app may open and what they may do (nsh/desktop’s
Window); None: no window of the app’s own. The first window needs
the grant too: no window is privileged.
Implementations§
Source§impl Capabilities
impl Capabilities
Sourcepub fn all() -> Capabilities
pub fn all() -> Capabilities
Legacy unrestricted APIs for apps without a declaration. Socket, process, filesystem and host function grants stay empty and always require explicit opt-in.
Sourcepub fn from_json(value: &Value) -> Result<Capabilities, String>
pub fn from_json(value: &Value) -> Result<Capabilities, String>
Parses capabilities strictly: unknown keys are errors. What NSH
itself reads (nsh.json, bundles, packages, grants) goes through
Capabilities::from_json_lenient, which a newer NSH’s keys do not
break.
Sourcepub fn from_json_lenient(
value: &Value,
) -> Result<(Capabilities, Vec<String>), String>
pub fn from_json_lenient( value: &Value, ) -> Result<(Capabilities, Vec<String>), String>
Parses capabilities a newer NSH may have written (nsh.json,
bundles, signed packages, grants): what it cannot read never grants
anything. An unknown capability is not granted; an unknown key inside
one (a restriction this runtime cannot apply) drops what it is in,
the whole capability or the http grant; a value of a form it does
not know drops its capability (or its http grant), and the others
stay. Declared capabilities allow only what they list, so what is
dropped is denied. Only a declaration that is no object is denied
whole. Returns what was dropped (capabilities.bluetooth, …) with
the capabilities.
Sourcepub fn to_json(&self) -> Value
pub fn to_json(&self) -> Value
The JSON form Capabilities::from_json reads.
Trait Implementations§
Source§impl Clone for Capabilities
impl Clone for Capabilities
Source§fn clone(&self) -> Capabilities
fn clone(&self) -> Capabilities
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Capabilities
impl Debug for Capabilities
Source§impl Default for Capabilities
impl Default for Capabilities
Source§fn default() -> Capabilities
fn default() -> Capabilities
impl Eq for Capabilities
Source§impl PartialEq for Capabilities
impl PartialEq for Capabilities
impl StructuralPartialEq for Capabilities
Auto Trait Implementations§
impl Forget for Capabilities
impl Freeze for Capabilitieswhere
*const u8 is !null: Freeze,
PhantomData<String>: Freeze,
PhantomData<HostPattern>: Freeze,
PhantomData<HttpGrant>: Freeze,
PhantomData<SocketGrant>: Freeze,
PhantomData<WebMedia>: Freeze,
PhantomData<WindowKind>: Freeze,
PhantomData<WindowLevel>: Freeze,
impl Move for Capabilities
impl RefUnwindSafe for Capabilities
impl Send for Capabilitieswhere
RawVecInner: Send,
impl Sync for Capabilitieswhere
RawVecInner: Sync,
impl Unpin for Capabilities
impl UnsafeUnpin for Capabilitieswhere
*const u8 is !null: UnsafeUnpin,
PhantomData<String>: UnsafeUnpin,
PhantomData<HostPattern>: UnsafeUnpin,
PhantomData<HttpGrant>: UnsafeUnpin,
PhantomData<SocketGrant>: UnsafeUnpin,
PhantomData<WebMedia>: UnsafeUnpin,
PhantomData<WindowKind>: UnsafeUnpin,
PhantomData<WindowLevel>: UnsafeUnpin,
impl UnwindSafe for Capabilitieswhere
RawVecInner: UnwindSafe,
Blanket Implementations§
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.