Skip to main content

Crate nsh_engine

Crate nsh_engine 

Source
Expand description

The engine thread of one surface.

The engine owns a nsh_core::Core on a dedicated thread and runs one app (App): a Rust app’s root component, or a JS bundle in a QuickJS VM (nsh_js::Host, feature js). Each wake-up (input event, timer, resize) runs the app’s code (component tasks; JS and its microtasks), applies what JS committed, lays out, and hands one MountBatch to the platform through a MountSink. The platform thread never blocks on the engine.

Re-exports§

pub use nsh_package as package;

Modules§

perf
Performance monitoring: what a surface’s frames and commits cost while it runs, for an on-screen monitor (--fps) or the app’s own tooling.

Structs§

Access
What an app may do: its declaration and the embedder’s grant (when the embedder limits it); an action must be allowed by both.
Bundle
An app bundle: its code plus, in development, a source map.
Capabilities
What an app may do (one declaration, or one grant).
Engine
A running engine. Dropping it stops the thread.
EngineConfig
Engine settings.
EngineControl
A cheap, cloneable handle for sending input to the engine from any thread.
Environment
What the platform knows about the surface.
HotUpdate
A development update that replaces the app’s changed modules in place, keeping the JS context, the views and the state of everything else (made by nsh_bundler::HotBundle::patch).
HttpHead
The status line and headers of a response, before its body.
HttpRequest
An HTTP request for the platform’s network stack (made by JS fetch).
Insets
Edge insets in points.
Limits
Resource limits of one VM.
LoadedPackage
A verified package, unpacked (load_package).
LocalEngine
An engine driven by its host’s event loop instead of a thread of its own: the browser’s main thread in WebAssembly, where there are no threads to block. Input sent through its EngineControl is handled at the next LocalEngine::pump.
Locale
A BCP 47 language tag (en-US, zh-Hans-CN), held inline so that the environment stays Copy: the language, script and region subtags fit; variants and extensions are dropped.
Policy
What a bundle’s code may do.
Root
The root of a Rust app: makes the app’s top component (on the engine thread, where elements live). The engine mounts it as the content of the surface (nsh_engine::App::Rust).
Theme
The theme components render with (super::RenderCx::theme). Derefs to its colors: theme.primary.

Enums§

App
The app an engine runs.
BundleCode
The code of a bundle.
ColorScheme
The system appearance.
FetchEvent
What happens to a request, in order: (for a streamed body) any number of BodyWanted; then Head, Data… and End — or Failed at any point.
FetchOp
What JS asks of a request it made (the JS host queues these for the engine, which hands them to the stack).
HttpBody
The body of an HttpRequest.
Idiom
The kind of device (React Native’s Platform.isPad, isTV).
Os
The operating system (Platform.OS).

Constants§

BYTECODE_VERSION
Identifies the bytecode format produced by compile_bytecode and accepted by crate::Host::eval_bytecode: QuickJS bytecode is only valid for the exact engine build. Bump together with the rquickjs pin.

Traits§

Assets
Reads the app’s bundled files (asset:/… URIs): from the app’s resources, or from the dev server during development.
FetchTask
A request in flight, driven from the engine thread.
MountSink
Receives mount batches on the engine thread. Implementations forward them to the UI thread.
Network
The platform’s HTTP stack, used by JS fetch.

Functions§

load_package
Verifies the package bytes with trust, writes its assets under assets_root (<root>/<app id>/<package hash>/, once per package) and records its build (older builds of the app are refused from now on).
parse_capabilities
Parses capabilities in their JSON form (capabilities.json, the dev protocol, an embedder’s grant).

Type Aliases§

FetchEvents
Receives what happens to a request started by Network::fetch, in order, on any thread. After FetchTask::cancel it may still be called (the engine then ignores it).