pub struct Registry { /* private fields */ }Expand description
Chain combinator for Resolver. Registration order = priority order. First match wins.
install() inserts a hook at the front (index 1) of Lua’s package.searchers
table, routing all require calls through the registered Resolver chain.
Takes priority over Lua’s standard package.preload.
Caching is delegated to Lua’s standard package.loaded.
Resolvers do not need to manage their own cache.
On the second and subsequent require for the same module, the Resolver is not called.
§Lua searcher protocol
The hook conforms to the Lua 5.4 searcher protocol:
- If the searcher returns a
function,requirecalls it as a loader - If the searcher returns a
string, it is collected as a “not found” reason in the error message
The loader receives (name, loader_data) (per Lua 5.4 spec).
§Thread safety
Registry itself is Send + Sync (all Resolvers must be Send + Sync).
After install(), the Registry is wrapped in Arc and
shared via a Lua closure.
Thread safety of the installed hook depends on the mlua feature configuration:
| mlua feature | Lua bounds | Implication |
|---|---|---|
| (default) | !Send | Lua is confined to one thread. The hook is never called concurrently. |
send | Send + Sync | Lua can be shared across threads. Resolver: Send + Sync ensures safe concurrent access. |
The Send + Sync bound on Resolver is required for forward compatibility
with mlua’s send feature. Without the send feature, Lua is !Send and
the hook is inherently single-threaded.
Implementations§
Source§impl Registry
impl Registry
pub fn new() -> Self
Sourcepub fn add(&mut self, resolver: impl Resolver + 'static) -> &mut Self
pub fn add(&mut self, resolver: impl Resolver + 'static) -> &mut Self
Add a Resolver. Registration order = priority order.
Sourcepub fn install(self, lua: &Lua) -> Result<()>
pub fn install(self, lua: &Lua) -> Result<()>
Insert a hook at the front of package.searchers.
Consumes self and shares it via Arc.
The Registry becomes immutable after install (Resolver priority is finalized).
Returns an error if called more than once on the same Lua instance. Multiple Registries coexisting in the same searchers table would make priority order unpredictable, so this is intentionally prohibited.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Registry
impl !RefUnwindSafe for Registry
impl Send for Registry
impl Sync for Registry
impl Unpin for Registry
impl UnsafeUnpin for Registry
impl !UnwindSafe for Registry
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