Skip to main content

Registry

Struct Registry 

Source
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, require calls 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 featureLua boundsImplication
(default)!SendLua is confined to one thread. The hook is never called concurrently.
sendSend + SyncLua 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

Source

pub fn new() -> Self

Source

pub fn add(&mut self, resolver: impl Resolver + 'static) -> &mut Self

Add a Resolver. Registration order = priority order.

Source

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§

Source§

impl Default for Registry

Source§

fn default() -> Self

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> 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, 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.
Source§

impl<T> MaybeSend for T