Skip to main content

PrefixResolver

Struct PrefixResolver 

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

Combinator that routes to an inner Resolver by name prefix.

Receives require("{prefix}{sep}{rest}"), strips the prefix and separator, and delegates {rest} to the inner Resolver. Returns None for names that don’t match the prefix.

§Match rules

Inputprefix=“sm”, sep=‘.’Result
"sm.helper"Strip "sm." -> "helper"Delegate to inner Resolver
"sm.ui.btn"Strip "sm." -> "ui.btn"Delegate to inner Resolver (multi-level)
"sm"No separator -> no matchNone (handled by outer Resolver)
"smtp"Does not start with "sm."None
"other.x"Prefix mismatchNone

§Design intent

require("sm") (package root = init.lua) is outside PrefixResolver’s scope. The outer FsResolver handles it via init.lua fallback. This clearly separates responsibilities:

  • PrefixResolver: sm.xxx -> submodules within the namespace
  • FsResolver: sm -> sm/init.lua (package entry point)

§Composition example

use mlua_pkg::{Registry, resolvers::*};
use mlua::Lua;

let lua = Lua::new();
let mut reg = Registry::new();

// "game.xxx" -> resolve within game_modules/
reg.add(PrefixResolver::new("game",
    MemoryResolver::new()
        .add("engine", "return { version = 2 }")
        .add("utils", "return { helper = true }")));

// "game" -> init.lua provided directly via MemoryResolver
reg.add(MemoryResolver::new()
    .add("game", "return { name = 'game' }"));

reg.install(&lua).unwrap();

// require("game.engine") -> PrefixResolver -> MemoryResolver("engine")
// require("game")        -> MemoryResolver("game")

Implementations§

Source§

impl PrefixResolver

Source

pub fn new(prefix: impl Into<String>, inner: impl Resolver + 'static) -> Self

Build a prefix router with . separator.

require("{prefix}.{rest}") -> inner.resolve("{rest}")

Source

pub fn with_convention(self, conv: LuaConvention) -> Self

Apply a LuaConvention in bulk.

Source

pub fn with_separator(self, separator: char) -> Self

Change the separator (default: .).

Trait Implementations§

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