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. - self
- Units and geometry, typed as GPUI’s
gpui::geometry: a length isPoints(GPUI’sPixels),Rems, aPercentage(a fraction:0.5is 50%) or one of the lengths styles give (AbsoluteLength,DefiniteLength,Length); an angle isRadians; shapes are generic over their unit (Point,Size,Bounds,Edges,Corners). Public API takes and returns these, never a baref32for a length, an angle or a fraction (held by theunit_typestest; docs/dev/geometry.md).
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.
- AppError
- An error of the app an engine runs. Its text (
fmt::Display) is the message and the stack, ascrate::MountSink::report_errorreceives it. - Bounds
- A rectangle: its top left corner (
origin) and itssize. A view’s frame is its bounds relative to its parent. - Bundle
- An app bundle: its code plus, in development, a source map.
- Byte
Size - A size in bytes, made from mebibytes or gibibytes (
ByteSize::mib(256)): how much a cache keeps at most. - Cache
Options - Where an app’s caches are kept and how much each keeps. The default: the system’s cache directory, each cache at its default size.
- Capabilities
- What an app may do (one declaration, or one grant).
Start with
Self::defaultand set the fields to grant; new capabilities default to denied. - Chunk
- A chunk of a split bundle (
nsh_bundler::Chunk): app code thatimport()loads on demand. - Clock
- The time an engine runs on: the system’s, or a manual clock that moves only when told, shared by the threads that drive the engine (a test’s).
- Edges
- A value for each edge of a box: insets, paddings, borders.
- Engine
- A running engine. Dropping it stops the thread.
- Engine
Config - Engine settings.
- Engine
Context - Typed values a host gives one engine (
EngineConfig::context), at most one per type, which its Rust code reads withengine_context. - Engine
Control - A cheap, cloneable handle for sending input to the engine from any thread.
- Environment
- What the platform knows about the surface.
- Environment
Pins - Values of the environment an engine keeps whatever its platform reports
(
EngineConfig::pinned);Noneleaves the platform’s. - File
Storage - An app’s storage kept in
storage.jsonof a directory: the app’s incrate::EngineConfig::data_dir, or one the embedding app chooses. - Host
Call - A call (
host.call(name, data)) or a post (host.post(name, data)) of the app, as the embedding app’s handler gets it. A call is answered once, from any thread; dropped unanswered, it fails in the app. - Host
Channel - The embedding app’s side of the channel with the apps one of its views
runs: launch parameters, events to the app (
host.onin TSX), and handlers of the app’s calls (host.call) and posts (host.post). - Host
Environment - The settings an embedding app gives its surfaces in place of the
system’s (
None: the system’s): its own language and text size, for an app inside a native app that lets its users switch them. The platforms write them over what they read from the system (Self::apply), so the app’sIntl,locale(),fontScale()and text follow them like a system change. - Host
Limits - The limits an embedding app sets for the apps it embeds (
NshLimitson iOS,NshView.setLimitson Android), and thosensh run --limitsruns an app with as such an app would: each one it leaves out keeps its default (Limits::default). - Host
Reply - How a call is answered (a
HostCall’s): once, from any thread. Dropped unanswered, the call fails in the app. - 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). - Http
Head - The status line and headers of a response, before its body.
- Http
Request - An HTTP request for the platform’s network stack (made by JS
fetchand by Rust components’crate::element::ambient::fetch). - Limits
- Resource limits of one VM.
- Loaded
Package - A verified package, unpacked (
load_package,verify_package). - Local
Engine - 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
EngineControlis handled at the nextLocalEngine::pump. - Locale
- A BCP 47 language tag (
en-US,zh-Hans-CN), held inline so that the environment staysCopy: the language, script and region subtags fit; variants and extensions are dropped. - Open
UrlRequest - A URL the app opens (
openUrlofnsh/device), as the embedding app’s URL handler gets it (HostChannel::handle_open_url). Answered once, from any thread:OpenUrlRequest::handledwhen the embedding app took it,OpenUrlRequest::declinefor the system to open it (also what dropping it unanswered does). - Package
Info - The signed package an app came from (
crate::Bundle::package): which release of it ran, for reports. - Point
- A point:
xto the right,ydown, from the origin of what it is relative to. - Points
- A length in points, the unit NSH lays out in (GPUI’s
Pixels): the platform’s density-independent unit (iOS / macOS points, Android dp, CSSpxon the web, DIPs on Windows). Style strings’pxand bare numbers are points. Device pixels areDevicePixels/ScaledPixels, met only where a platform draws or reports them. - 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). - Size
- A width and a height.
- Tokens
- Design tokens by name: colors with a value per appearance, numbers and font families. The default has none.
Enums§
- App
- The app an engine runs.
- AppError
Kind - What went wrong (
AppError::kind). - Bundle
Code - The code of a bundle.
- Cache
Location - The root directory of an app’s caches.
- Cache
Policy - How much one cache keeps.
- Color
Scheme - The system appearance.
- Fetch
Event - What happens to a request, in order: (for a streamed body) any number
of
BodyWanted; thenHead,Data… andEnd— orFailedat 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).
- Http
Body - The body of an
HttpRequest. - Idiom
- The kind of device (
platform.idiom). - Json
Value - The values registered native components take and emit (props, events, command arguments): JSON. Represents any valid JSON value.
- Os
- The operating system (
platform.os). - Storage
Change - A change to the entries, for the backend to keep.
Constants§
- BYTECODE_
VERSION - Identifies the bytecode format produced by
compile_bytecodeand accepted bycrate::Host::eval_bytecode: the QuickJS-NG release and revision, its bytecode format (BC_VERSION) and the byte order written.
Traits§
- Assets
- Reads the app’s bundled files (
asset:/…URIs): from the app’s resources, or from the dev server during development. - Fetch
Task - A request in flight, driven from the engine thread.
- Mount
Sink - Receives mount batches on the engine thread. Implementations forward them to the UI thread.
- Network
- The platform’s HTTP stack, used by JS
fetch. - Storage
Backend - Where an app’s entries are kept: the platform’s.
Functions§
- accept_
package - Records the build of
package(verify_package) intrust: older builds of its app are refused from now on. Refused if the package or its release key was revoked since it was verified. - app_
dir_ name - The directory of app
idin a data directory: the id, ordefaultfor an app without one, or one that is no directory name. - data_
dir - The system’s directory for apps’ data: Application Support on Apple
platforms,
%APPDATA%on Windows,$XDG_DATA_HOME(~/.local/share) elsewhere.Noneon Android, whose files directory only the platform knows, and without a home directory. An app of its own keeps its data in<data_dir>/<app id>(crate::EngineConfig::data_dir). - load_
package - Verifies the package
byteswithtrust, writes its assets underassets_root(<root>/<app id>/<package hash>/, once per package) and records its build (older builds of the app are refused from now on):verify_package, thenaccept_package. - local_
storage_ prefix - The prefix of the
localStoragekeys of appapp_idon the page aturl(document.baseURI):nsh:com.example.todo:; without an id,nsh:/apps/todo/:forhttps://x.com/apps/todo/index.html?a#b. - parse_
capabilities - Parses capabilities in their JSON form (
capabilities.json, the dev protocol, an embedder’s grant). - symbolicate
- Rewrites every
bundle.js:LINE:COLintext(a reported error and its stack) to the app source positionsource_map(the bundle’s) gives, as the engine does with a bundle’s own map: for stacks reported by packages published without their map (nsh symbolicate). - verify_
package load_packagewithout recording the build: the package is verified as strictly (signature, certificate, revocations, hashes, and its build not older than the highest accepted) and its assets written, but the builds accepted before keep verifying. An embedding app runs it, and once it decided the package is healthy (its first frame drawn, no fatal error for a while) callsaccept_package; if it fails before, the app can go back to the package it ran before, which still verifies.
Type Aliases§
- Fetch
Events - Receives what happens to a request started by
Network::fetch, in order, on any thread. AfterFetchTask::cancelit may still be called (the engine then ignores it).