Skip to main content

Module resource

Module resource 

Source
Expand description

Bundled-resource random-access API + the per-backend ResourceOpener hook (§18.3). Bundled resources: efficient random read-only access to app-declared data, backed by each toolkit’s native resource mechanism (DESIGN.md §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§

AssetDir
A bundled-asset directory (§18.5): a folder’s path relative to resource/assets/, /-separated, no trailing slash. The generated res::assets::… tree carries one constant per folder, sharing its module’s name: res::assets::web::minisite is the AssetDir and res::assets::web::minisite::index_html a file within it.
AssetName
The bundled-data name that resource resolves by: the file’s path relative to resource/assets/, /-separated (a top-level file is just its 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 resource() 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 resource() 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).

Constants§

WEIGHT_SUFFIXES
The suffixes Vector::weight appends to a glyph name (docs/vectors.md).

Functions§

resolve_asset_dir
Resolve a data-asset directory (an AssetDir’s /-relative path) to its on-disk location, for consumers whose local-content channel is a file URL, like the inline web view on the Apple backends (day-piece-webview’s docs/webview.md). Same probe order as file resolution: DAY_ASSET_ROOT (dev / day launch), then the bundle-relative roots.
resolve_asset_file
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.
resolve_vector_svg
Resolve a vector name to its staged glyph SVG, for backends that render SVG natively (docs/vectors.md): DAY_VECTOR_SVG_ROOT under day launch, else the packed layouts: Contents/Resources/vectors/svg in a .app, vectors/svg beside a flat-layout exe. None (name isn’t a vector, or the layout carries no SVGs) means fall back to resolve_image_file’s raster resolution.
resolve_vector_xaml
Resolve a vector name to its staged XAML geometry (docs/vectors.md), the form day-xaml draws as real Path geometry: vector at any size, and tintable by brush at runtime. DAY_VECTOR_XAML_ROOT under day launch, else vectors/xaml beside a flat-layout exe. None (name isn’t a vector, the art was outside the convertible subset, or the layout carries no geometry) means fall back to resolve_image_file’s raster resolution.
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.
stage_symbol_svg
Day’s own drawing of sym, written to a cache file and answered as a path.
weight_alias
The base glyph a weight-suffixed name aliases, or None if the name carries no suffix.

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