Skip to main content

Bundle

Struct Bundle 

Source
#[non_exhaustive]
pub struct Bundle {
Show 13 fields pub code: BundleCode, pub source_map: Option<Arc<str>>, pub policy: Policy, pub base_url: Option<Arc<str>>, pub chunks: Arc<Vec<Chunk>>, pub app_id: Option<String>, pub links: AppLinks, pub system_paths: TrustedPaths, pub package: Option<Arc<PackageInfo>>, pub updater_config: Option<Arc<[u8]>>, pub trial: Option<Arc<dyn Trial>>, pub main_window: Option<MainWindowOptions>, pub application: Option<ApplicationOptions>,
}
Expand description

An app bundle: its code plus, in development, a source map.

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.
§code: BundleCode

The code.

§source_map: Option<Arc<str>>

Source map (JSON) used to show app source locations in stack traces.

§policy: Policy

What the code may do.

§base_url: Option<Arc<str>>

What relative request URLs resolve against (the page’s URL on the web); None: they are invalid.

§chunks: Arc<Vec<Chunk>>

The chunks of a split bundle that come with it (import() loads them without asking the platform); those missing are asked of MountSink::load_chunk. Shared by the bundle’s clones.

§app_id: Option<String>

The app’s id (nsh.json "id"; a signed package’s verified one): it names where the app keeps its data (nsh/storage).

§links: AppLinks

The links the app claims (nsh.json schemes and links, a packaged app’s app.json): the URLs of its schemes and the https URLs of its web links its engine lets through. Read from the app’s own resources, never from its code; none for a signed package, whose embedding app owns them.

§system_paths: TrustedPaths

Trusted filesystem anchors selected by the native host, never decoded from application code, its manifest or a development server message. Missing anchors deny relative and corresponding placeholder grants.

§package: Option<Arc<PackageInfo>>

The signed package the bundle came from (Bundle::from_package), named in the app’s errors (AppError::package).

§updater_config: Option<Arc<[u8]>>

The update configuration nsh/updater reads (nsh-updater.json, as nsh package wrote it), from the installed app’s own resources; None: the file among the app’s assets, if any. A packaged app running a newer package of its code sets the shipped one (updates::launch).

§trial: Option<Arc<dyn Trial>>

Told how the app fares, while it has not proved it runs: a package of a packaged app’s code running for the first time (updates::launch).

§main_window: Option<MainWindowOptions>

The main window’s launch-time options (nsh.json "window", an app’s app.json, the dev server’s app info): runners read them before they make the window; the engine sends their attributes to the first window.

§application: Option<ApplicationOptions>

The app’s lifecycle options (nsh.json "application", an app’s app.json, the dev server’s app info): the engine sets the quit policy before the app’s code runs.

Implementations§

Source§

impl Bundle

Source

pub unsafe fn bytecode(bytes: Vec<u8>) -> Self

A bytecode bundle.

§Safety

bytes must be bytecode from nsh_js::compile_bytecode for this runtime’s BYTECODE_VERSION, from a trusted source: QuickJS does not validate bytecode, and loading crafted bytecode corrupts memory. Trusted are the app’s own signed resources, a development server the developer pointed the host at, and verified packages (Bundle::from_package).

Source

pub fn source(code: String) -> Self

A JS source bundle.

Source

pub fn with_system_paths(self, paths: TrustedPaths) -> Self

Selects trusted source/package and home directory anchors. Supplying a path grants nothing by itself: the manifest and host grant must still allow the filesystem operation. Only existing absolute directories are accepted; unavailable anchors are left unset.

Source

pub fn with_app_id(self, id: Option<&str>) -> Self

The app’s id (Bundle::app_id), as nsh.json or the dev server gives it.

Source

pub fn with_main_window(self, json: Option<&str>) -> Self

The main window’s launch-time options from their JSON (nsh.json "window", as the dev server’s app info carries it); a wrong one is logged and left out.

Source

pub fn with_application(self, json: Option<&str>) -> Self

The app’s lifecycle options from their JSON (nsh.json "application", as the dev server’s app info carries it); a wrong one is logged and left out.

Source

pub fn with_url_schemes( self, schemes: impl IntoIterator<Item = impl Into<String>>, ) -> Self

The URL schemes the app claims, as nsh.json gives them: those of Bundle::links, whose web links stay.

The links the app claims (Bundle::links).

Source

pub fn with_source_map(self, map: impl Into<Arc<str>>) -> Self

Attaches a source map.

Source

pub fn with_base_url(self, url: impl Into<Arc<str>>) -> Self

Sets the URL relative request URLs resolve against: the page’s, for an app on a web page. A base marks a page: with one, a media source /x is the page’s path, not a local file under capabilities.fs (nsh_core::access::Access::media_url), so a native host sets none.

Source

pub fn with_policy(self, policy: Policy) -> Self

Replaces the policy.

Source

pub fn with_chunks(self, chunks: impl IntoIterator<Item = Chunk>) -> Self

Adds chunks of a split bundle (see Bundle::chunks).

Source

pub fn read(path: &Path) -> Result<Bundle>

Reads a JS source bundle written by nsh build (bundle.js), plus bundle.js.map, the app’s capabilities.json, its id and the schemes it claims (app.json "id" and "schemes") next to it if present. Bytecode (bundle.nshc) is refused: files can be replaced, and only Bundle::read_trusted (the app’s own resources) or a verified package may load bytecode.

Source

pub unsafe fn read_trusted(path: &Path) -> Result<Bundle>

Like Bundle::read, also reading bundle.nshc as bytecode.

§Safety

A .nshc file must be trusted as Bundle::bytecode requires (e.g. inside the app’s own signed bundle).

Source§

impl Bundle

Source

pub fn from_package(package: &VerifiedPackage) -> Result<Bundle, String>

The bundle of a verified package: its bytecode when it was compiled for this runtime (else its source), its source map and its declared capabilities. What a newer signer wrote that this runtime does not know (header fields, files, capabilities) is logged and left out: an unknown capability is not granted.

Source§

impl Bundle

Source

pub fn with_capabilities_json(self, json: Option<&str>) -> Result<Self, String>

The declared capabilities from their JSON form, if any.

Trait Implementations§

Source§

impl Clone for Bundle

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 Bundle

Source§

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

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

impl Default for Bundle

Source§

fn default() -> Self

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

impl From<Bundle> for App

Source§

fn from(bundle: Bundle) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Bundle

§

impl !UnwindSafe for Bundle

§

impl Forget for Bundle

§

impl Freeze for Bundle

§

impl Move for Bundle

§

impl Send for Bundle

§

impl Sync for Bundle

§

impl Unpin for Bundle

§

impl UnsafeUnpin for Bundle

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> 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> ParallelSend for T

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
Source§

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

Source§

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