pub struct Bundle {
pub entry: String,
pub fingerprint: Vec<u8>,
pub htl_version: String,
pub host_modules: Vec<String>,
pub modules: Vec<Module>,
}Expand description
A whole program as one file: decoded from bytes,
encoded back to them, and installed into a state by
Htl::install_bundle.
Fields§
§entry: StringThe module to run once the rest are registered. A name in modules, not a path.
fingerprint: Vec<u8>Lua bytecode header of the compiling state (see crate::Htl::fingerprint);
empty when no module is bytecode.
htl_version: StringWhich htl built this, for the mismatch message. Advisory — a bundle from an older htl whose fingerprint agrees still loads — and recorded because the Lua chunk header cannot tell one 5.4.x from another, so nothing else says which Lua produced the bytes.
host_modules: Vec<String>require names the bundle expects the host to provide (Rust #[host_module]s,
preloads): declared only by a .d.tl at link time, or listed in [build] host.
modules: Vec<Module>Every module the entry’s require closure reached, the entry included. Order is the
linker’s; require finds them by name, so nothing depends on it.
Implementations§
Source§impl Bundle
impl Bundle
Sourcepub fn is_bundle(bytes: &[u8]) -> bool
pub fn is_bundle(bytes: &[u8]) -> bool
Whether these bytes are a bundle of either format — the question a caller holding
an unknown file asks before decode, which fails on anything else.
Sourcepub fn module(&self, name: &str) -> Option<&Module>
pub fn module(&self, name: &str) -> Option<&Module>
The module registered under name, or None when the bundle does not carry it —
which for a name in host_modules is the expected answer.
A scan rather than a map: a bundle is decoded once and read a handful of times, and building an index would cost more than the walks it saves.
Sourcepub fn encode(&self) -> Vec<u8> ⓘ
pub fn encode(&self) -> Vec<u8> ⓘ
The bytes, in the format at the top of this module. Always the current version —
HTLB\x01 is decoded for bundles that already exist and never written.
Sourcepub fn decode(bytes: &[u8]) -> Result<Self>
pub fn decode(bytes: &[u8]) -> Result<Self>
A bundle of either format, read from bytes.
Both versions land in this one struct, so a caller does not branch on which it was
given; format_version is there for the one that wants to say. A version 1
bundle carries no fingerprint, htl version or host modules, and its every module is
bytecode, so those fields come back empty rather than guessed at.
Every failure is about the bytes — bad magic, truncated, a module kind this build
does not know, a name that is not UTF-8 — and none of them is about the Lua inside.
Whether the bytecode loads is Htl::install_bundle’s
question, and it is asked against the fingerprint this returns.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Bundle
impl RefUnwindSafe for Bundle
impl Send for Bundle
impl Sync for Bundle
impl Unpin for Bundle
impl UnsafeUnpin for Bundle
impl UnwindSafe for Bundle
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more