Reference

std/resource/resource

std/resource/src/resource.trb

Resource, EmbeddedBytes and EmbeddedText: the three types a string literal names a file of the package with (docs/design/RESOURCES.md section 4). They are capsules over the stable name the compiler resolved - the owner and name of the package, then the path inside it, always with / - so the only way to make one is a literal.

type Resource

type Resource with Show, Equals, Hash

A file that ships with the program and is read while it runs, found relative to the program and never to the working directory. A literal where a Resource is expected names a file of the package, relative to the file that writes it.

Examples

fn load(sheet: Resource): String {
  sheet.name()
}

Pitfalls

  • A path is compared byte for byte on every platform: ./Hero.png next to hero.png is an error on Windows too.
  • A String value is never a resource: a path chosen while the program runs is a Path, read through std/fs.

fn name

fn name(): String

What the file is called: acme/game/src/sheets/hero.spr, the text a diagnostic and a log print.

fn show

fn show(): String

Not documented.

type EmbeddedBytes

type EmbeddedBytes with Show, Equals, Hash

A file whose bytes are in the binary. Reading them cannot fail: the compiler has the file in its hands.

fn name

fn name(): String

What the file is called: its stable name.

fn show

fn show(): String

Not documented.

type EmbeddedText

type EmbeddedText with Show, Equals, Hash

A file whose text is in the binary, so reading it cannot fail: the compiler reads the file, and checks its UTF-8, where the literal names it (slice 2 of docs/design/RESOURCES.md).

fn name

fn name(): String

What the file is called: its stable name.

fn show

fn show(): String

Not documented.