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
| Input | prefix=“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 match | None (handled by outer Resolver) |
"smtp" | Does not start with "sm." | None |
"other.x" | Prefix mismatch | None |
§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
impl PrefixResolver
Sourcepub fn new(prefix: impl Into<String>, inner: impl Resolver + 'static) -> Self
pub fn new(prefix: impl Into<String>, inner: impl Resolver + 'static) -> Self
Build a prefix router with . separator.
require("{prefix}.{rest}") -> inner.resolve("{rest}")
Sourcepub fn with_convention(self, conv: LuaConvention) -> Self
pub fn with_convention(self, conv: LuaConvention) -> Self
Apply a LuaConvention in bulk.
Sourcepub fn with_separator(self, separator: char) -> Self
pub fn with_separator(self, separator: char) -> Self
Change the separator (default: .).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PrefixResolver
impl !RefUnwindSafe for PrefixResolver
impl Send for PrefixResolver
impl Sync for PrefixResolver
impl Unpin for PrefixResolver
impl UnsafeUnpin for PrefixResolver
impl !UnwindSafe for PrefixResolver
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
Mutably borrows from an owned value. Read more
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>
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 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>
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