Skip to main content

Bundle

Struct Bundle 

Source
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: String

The 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: String

Which 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

Source

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.

Source

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.

Source

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.

Source

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§

Source§

impl Clone for Bundle

Source§

fn clone(&self) -> Bundle

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Bundle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Bundle

Source§

fn default() -> Bundle

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> MaybeSend for T

Source§

impl<T> MaybeSync for T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.