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 ituses(one level, the same mixin rulecrate::assets::compose_unit_assetsapplies to assets). A local declaration of any kind wins over an imported embed of the same name; two used commons declaring the same name isbynk.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\nand a bare\rbecome\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 isbynk.embed.duplicate; an asset, a free function or a type isbynk.resolve.name_conflict(an embed is a value, in the function namespace, and a type name in value position is an error).Nonewhen 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_projectfore: a single-file build emits one module and has no project root to findembeds/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_dirfore, 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.envor a source file into a bundle by mistake.- path_
errors - The path rules for
e, in order:unsafe_path_error, thenoutside_embeds_dir_error(at most one of the two applies). - phase_
embed_ files bynk.embed.missing_filefor each embed whose (otherwise valid) path names no file inavailable— the project’sembeds/folder as the caller read it.Noneskips the check: nothing on disk was consulted (an in-memory check). A build passesSome, 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_commonsfore.- 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 failspath_errorsor names no listed file is skipped (phase_embed_filesreports the latter). A listed file the reader fails on isbynk.embed.unreadable_file; one that is not text isbynk.embed.invalid_encodingorbynk.embed.binary_content; one overMAX_EMBED_BYTES, or that takes the declared files pastMAX_EMBEDS_TOTAL_BYTES, isbynk.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, whenbuildis set, its refusal (needs_project_error). Placement needs no check here: a single file is always a commons (anadapteris a parse error). - unsafe_
path_ error bynk.embed.unsafe_pathfore, 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.