Skip to main content

VendoredResolver

Struct VendoredResolver 

Source
pub struct VendoredResolver { /* private fields */ }
Expand description

Resolver that exposes the .mlua-pkgs/vendored/ directory to require.

VendoredResolver is a thin wrapper over FsResolver rooted at the vendored_root directory (typically .mlua-pkgs/vendored/).

Each package in that directory is expected to be a symlink (or real directory) created by the mlua-pkg install CLI (ST5). For example, require("foo") resolves to vendored/foo/init.lua, and require("foo.bar") resolves to vendored/foo/bar.lua.

§Responsibilities

  • This resolver reads — it does not create symlinks or directories.
  • The CLI createsmlua-pkg install is responsible for populating .mlua-pkgs/vendored/ before this resolver is used.

§Construction

ConstructorUse when
VendoredResolver::from_lockfileNormal usage: lockfile path + vendored root
VendoredResolver::newLow-level: vendored root already exists and is populated

§Errors

new() returns InitError::RootNotFound if vendored_root does not exist. from_lockfile() returns [PkgError::MissingLockfile] if the lockfile is absent, or [PkgError::SameNameConflict] if duplicate package names are found.

Implementations§

Source§

impl VendoredResolver

Source

pub fn new(vendored_root: impl Into<PathBuf>) -> Result<Self, InitError>

Low-level constructor: wrap an existing vendored_root directory.

Does not read a lockfile. Use from_lockfile for the normal flow.

§Errors

Returns InitError::RootNotFound if vendored_root does not exist.

Source

pub fn from_lockfile( lockfile_path: impl AsRef<Path>, vendored_root: impl AsRef<Path>, ) -> Result<Self, PkgError>

Normal constructor: read lockfile_path and wrap vendored_root.

Reads and validates the lockfile, then constructs an FsResolver rooted at vendored_root. For each package in the lockfile, emits a tracing::warn! if the corresponding vendored_root/<name> symlink or directory is absent (the CLI has not yet installed that package). Resolution will simply return None for missing packages at runtime, matching normal FsResolver miss behaviour.

vendored_root is created automatically if it does not exist, to avoid requiring a prior mlua-pkg install just to construct the resolver.

§Errors
ErrorCondition
[PkgError::MissingLockfile]lockfile_path does not exist
[PkgError::LockfileParse]Invalid TOML in the lockfile
[PkgError::SameNameConflict]Duplicate package names in the lockfile
[PkgError::Io]I/O failure while creating vendored_root or reading the lockfile

Trait Implementations§

Source§

impl Debug for VendoredResolver

Source§

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

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

impl Resolver for VendoredResolver

Source§

fn resolve(&self, lua: &Lua, name: &str) -> Option<Result<Value>>

Delegate resolution to the inner FsResolver.

require("foo") resolves to vendored/foo.lua or vendored/foo/init.lua. require("foo.bar") resolves to vendored/foo/bar.lua.

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.