Skip to main content

Module embeds

Module embeds 

Source
Expand description

#2387 (embedded text): the checker-side rules for embed name = "path" declarations — the path rules, the name rule, the composition of a unit’s visible embeds through uses — mirroring crate::assets for the part an embed shares with an asset.

An embed is a project file’s text compiled into the code as a String constant. Unlike an asset it is never served, so it is private, and it comes from the project’s embeds/ folder instead of assets/.

The checker stays disk-free: the folder reaches it from the caller as a bynk_project::assets::EmbedFolder, and read_declared_embeds reads only the files a declaration names, applying the content rules (embedded_text) and the size caps.

Constants§

MAX_EMBEDS_TOTAL_BYTES
The most bytes a project’s declared embeds may total (each file counted once, however many declarations name it).
MAX_EMBED_BYTES
The largest embedded file, in bytes. The text lands in the Worker bundle and counts against the platform’s script size limits, so an embed is for markup and prose, not data.

Functions§

compose_unit_embeds
Every embed visible in unit name: its own, plus those of each commons it uses (one level, the same mixin rule crate::assets::compose_unit_assets applies to assets). A local declaration of any kind wins over an imported embed of the same name; two used commons declaring the same name is bynk.uses.name_conflict (phase_uses_name_conflicts), so which of them is kept here is never observable in a program that checks.
embedded_text
The text a file’s bytes embed as, or why they cannot be: valid UTF-8 (bynk.embed.invalid_encoding) with no NUL byte (bynk.embed.binary_content). A leading byte-order mark is dropped and \r\n and a bare \r become \n, so the same source builds to the same constant whatever a checkout’s line-ending settings do. Everything else, including a trailing newline, is kept as is.
name_error
The name rule for embed e, given what its unit already declares under that name: an earlier embed is bynk.embed.duplicate; an asset, a free function or a type is bynk.resolve.name_conflict (an embed is a value, in the function namespace, and a type name in value position is an error). None when the name is free. One rule for the project pipeline (symbols::build_unit_table) and the single-file compile, which has no unit table.
needs_project_error
bynk.embed.needs_project for e: a single-file build emits one module and has no project root to find embeds/ under, so it cannot read the file. Checking a single file is unaffected; building one that declares an embed is refused. Build the project instead.
outside_embeds_dir_error
bynk.embed.outside_embeds_dir for e, when its path is safe but does not lie inside the project’s embeds folder (bynk_project::assets::PROJECT_EMBEDS_DIR). An embed is compiled into the deployed code, so it comes only from that folder, and a declaration can never pull .env or a source file into a bundle by mistake.
path_errors
The path rules for e, in order: unsafe_path_error, then outside_embeds_dir_error (at most one of the two applies).
phase_embed_files
bynk.embed.missing_file for each embed whose (otherwise valid) path names no file in available — the project’s embeds/ folder as the caller read it. None skips the check: nothing on disk was consulted (an in-memory check). A build passes Some, an empty set when it had no filesystem, so it never invents text for a file nobody read.
placement_error
bynk.embed.outside_context_or_commons for e.
read_declared_embeds
The text of every declared embed file in folder, keyed by normalised path — read through the folder’s reader once each, and only for a file a declaration names. A declaration whose path fails path_errors or names no listed file is skipped (phase_embed_files reports the latter). A listed file the reader fails on is bynk.embed.unreadable_file; one that is not text is bynk.embed.invalid_encoding or bynk.embed.binary_content; one over MAX_EMBED_BYTES, or that takes the declared files past MAX_EMBEDS_TOTAL_BYTES, is bynk.embed.too_large. Each is reported on every declaration that names the file, and the file is left out.
single_file_embed_errors
The single-file compile’s embed diagnostics, in declaration order: each embed’s path check and name rule (name_error, against the file’s own assets, functions, types and earlier embeds), and, when build is set, its refusal (needs_project_error). Placement needs no check here: a single file is always a commons (an adapter is a parse error).
unsafe_path_error
bynk.embed.unsafe_path for e, when its path is empty, absolute or contains a .. segment. The same rule as an asset’s path (crate::assets::unsafe_asset_path_reason): the path is joined onto the project root to find the file, so nothing outside the project may be named.