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. 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 creates —
mlua-pkg installis responsible for populating.mlua-pkgs/vendored/before this resolver is used.
§Construction
| Constructor | Use when |
|---|---|
VendoredResolver::from_lockfile | Normal usage: lockfile path + vendored root |
VendoredResolver::new | Low-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
impl VendoredResolver
Sourcepub fn new(vendored_root: impl Into<PathBuf>) -> Result<Self, InitError>
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, so it knows no per-package entry:
every vendored/<name> is treated as the require root itself.
mlua-pkg install links vendored/<name> to the package root,
so packages whose entry is a subdirectory (src/, lua/, …) only
resolve through from_lockfile /
from_lock.
§Errors
Returns InitError::RootNotFound if vendored_root does not exist.
Sourcepub fn from_lockfile(
lockfile_path: impl AsRef<Path>,
vendored_root: impl AsRef<Path>,
) -> Result<Self, PkgError>
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
| Error | Condition |
|---|---|
[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 |
Sourcepub fn from_lock(
lockfile: &Lockfile,
vendored_root: impl AsRef<Path>,
) -> Result<Self, PkgError>
pub fn from_lock( lockfile: &Lockfile, vendored_root: impl AsRef<Path>, ) -> Result<Self, PkgError>
Same as from_lockfile but with an in-memory
Lockfile — for callers that already
hold the value (e.g. from an
InstallReport-driven flow) and do not
want the resolver to re-read mlua-pkg.lock.
§Errors
PkgError::Iowhenvendored_rootcannot be created or opened.
Trait Implementations§
Source§impl Debug for VendoredResolver
impl Debug for VendoredResolver
Source§impl Resolver for VendoredResolver
impl Resolver for VendoredResolver
Source§fn resolve(&self, lua: &Lua, name: &str) -> Option<Result<Value>>
fn resolve(&self, lua: &Lua, name: &str) -> Option<Result<Value>>
Delegate resolution to the inner FsResolver, inserting the
package’s entry after its name.
With entry = "src" for foo: require("foo") resolves to
vendored/foo/src/init.lua (or vendored/foo/src.lua), and
require("foo.bar") to vendored/foo/src/bar.lua. With a trivial
entry (".") the name is used as is: vendored/foo/init.lua,
vendored/foo/bar.lua.
Auto Trait Implementations§
impl !RefUnwindSafe for VendoredResolver
impl !UnwindSafe for VendoredResolver
impl Freeze for VendoredResolver
impl Send for VendoredResolver
impl Sync for VendoredResolver
impl Unpin for VendoredResolver
impl UnsafeUnpin for VendoredResolver
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> 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