Skip to main content

Module resource

Module resource 

Source
Expand description

Bundled-resource random-access API + the per-backend opener seam (§18.3). Bundled resources — efficient random read-only access to app-declared data, backed by each toolkit’s native resource mechanism (DESIGN §18.3).

day build stages the files declared under a project’s assets/ (and images/) into each platform’s native resource store, uncompressed where possible so the runtime can hand back a zero-copy view. At runtime resource("name") returns a Resource whose bytes are borrowed directly from that store — an mmap of a bundle file on Apple, the NDK AAssetManager buffer on Android, g_resources_lookup_data on GTK, QResource::data on Qt, the rawfile fd on ArkUI.

The active backend registers its opener once via set_resource_opener; if none is registered (desktop dev, host tests, and the Apple backends, whose native mechanism is a bundle file) the default opener mmaps the file resolved from DAY_ASSET_ROOT or the app bundle.

Structs§

AssetName
The bundled-data name that resource resolves by (the full file name, extension included).
FontFamily
The family name of a bundled custom font, feeding Font::custom. Holds a &'static str (so Font stays Copy); generated res::fonts::… constants supply it. The untyped Font::Custom(&'static str, f64) variant remains the escape hatch for a family known another way.
ImageName
The bundled-image name that image callers resolve by (the file stem).
Resource
A handle to a bundled resource’s bytes with efficient random read-only access.
VectorName
The bundled-vector name that vector callers resolve by (docs/vectors.md): the stem of a resource/vectors/ SVG (or .symbolset bundle). Vectors and images share one per-backend resolution namespace — staging guarantees every vector name resolves as whatever form that backend loads natively (a VectorDrawable, a catalog entry, a rasterized PNG).

Functions§

resolve_image_file
Resolve an image name to an on-disk file, for the file-loading backends (AppKit/GTK/Qt, and the desktop/dev path). Probes DAY_IMAGE_ROOT (the project’s images/ under day launch) first, then DAY_ASSET_ROOT and the bundle, trying the bare name and, if it has no extension, each known image extension. Native-pipeline backends (iOS Assets.car, Android R, …) resolve by name through their own store and do not use this.
resource
Open a bundled resource by name for efficient random read-only access.
set_resource_opener
Register the active backend’s resource opener (Android AAssetManager, GTK GResource, Qt QResource, ArkUI rawfile, …). Called once during backend init. A second call is ignored, so a backend that shares the default file opener need not call this at all.

Type Aliases§

ResourceOpener
A backend’s resource opener: maps a declared name (e.g. "stations.json") to its bytes, or None if there is no such resource.
Day API ↩ Guides· daybrite.dev