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.pngnext tohero.pngis an error on Windows too. - A
Stringvalue is never a resource: a path chosen while the program runs is aPath, read throughstd/fs.
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.
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).