pub struct modulestab {
pub modules: HashMap<String, module>,
pub autoload_builtins: HashMap<String, String>,
pub autoload_conditions: HashMap<String, String>,
pub autoload_params: HashMap<String, String>,
pub autoload_mathfuncs: HashMap<String, String>,
pub added_builtins: HashMap<String, u32>,
}Expand description
Module table (from module.c module hash table)
Table of registered modules.
Port of the modulestab HashTable Src/module.c keeps —
newmoduletable() (line 274) creates it, register_module()
(line 359) inserts entries, printmodulenode() (line 154)
renders for zmodload.
Fields§
§modules: HashMap<String, module>modules field.
autoload_builtins: HashMap<String, String>Builtin name → module name mapping for autoload
autoload_conditions: HashMap<String, String>Condition name → module name mapping for autoload
autoload_params: HashMap<String, String>Parameter name → module name mapping for autoload
autoload_mathfuncs: HashMap<String, String>Math function name → module name mapping for autoload
added_builtins: HashMap<String, u32>BINF_ADDED ledger — tracks which builtins have been added via
setbuiltins (C: b->node.flags & BINF_ADDED, c:508).
Implementations§
Source§impl modulestab
impl modulestab
Sourcepub fn load_module(&mut self, name: &str) -> bool
pub fn load_module(&mut self, name: &str) -> bool
Port of int load_module(char const *name, Feature_enables enablesarr, int silent) from Src/module.c:2206. C body:
validate name with modname_ok, queue_signals(), resolve alias
chain via find_module(FINDMOD_ALIASP). If not found, attempt
module_linked then do_load_module (dlopen). Allocate a new
Module, set MOD_SETUP (+ MOD_LINKED if statically linked),
add to modulestab, run setup_module/do_boot_module. If
either fails, cleanup+finish+delete and return 1. Else clear
MOD_SETUP, set MOD_INIT_S | MOD_INIT_B, return bootret.
If found and already MOD_SETUP, return 0. Detect circular
deps via MOD_BUSY, load dependency list recursively. zshrs:
all modules are statically linked, so dlopen path is skipped
and we operate on the static registry.
WARNING: param names don’t match C — Rust=(name) vs C=(name, enablesarr, silent)
Sourcepub fn unload_module(&mut self, name: &str) -> bool
pub fn unload_module(&mut self, name: &str) -> bool
Port of int unload_module(Module m) from Src/module.c:2817.
C body: resolve MOD_ALIAS via find_module(FINDMOD_ALIASP);
if MOD_INIT_S set and !MOD_UNLOAD, call do_cleanup_module.
Clear MOD_INIT_B|MOD_INIT_S. If a wrapper is present, set
MOD_UNLOAD and bail (deferred). Else clear MOD_UNLOAD and
call m->u.linked->finish(m) or finish_module(m) depending
on MOD_LINKED. Finally walk m->deps and unload modules
that were tagged MOD_UNLOAD when the last dependent dies.
WARNING: param names don’t match C — Rust=(name) vs C=(m)
Sourcepub fn is_bound(&self, name: &str) -> bool
pub fn is_bound(&self, name: &str) -> bool
Whether a module is BOUND — its setup_/boot_ has actually run.
Mirrors the zmodload -e existence test (bin_zmodload_exist,
c:Src/module.c:2637): the union slot m->u.handle is non-NULL
(handle for dlopen, linked for a static module) and the module is
not mid-unload. Distinct from is_loaded() / module_loaded(),
which key off MOD_LINKED — a flag register_builtin_modules
pre-seeds for every statically-compiled module at startup, so it
is true before zmodload ever runs. Use this for “was the module
actually loaded by the user” gates.
Sourcepub fn list_loaded(&self) -> Vec<&str>
pub fn list_loaded(&self) -> Vec<&str>
List all loaded modules
Sourcepub fn list_all(&self) -> Vec<(&str, i32)>
pub fn list_all(&self) -> Vec<(&str, i32)>
List all modules (including unloaded). Returns name + raw
MOD_* flag bits — caller can inspect MOD_UNLOAD / MOD_LINKED
directly (matches C, which exposes m->node.flags).
Sourcepub fn addbuiltin(&mut self, name: &str, module: &str) -> i32
pub fn addbuiltin(&mut self, name: &str, module: &str) -> i32
Register a builtin (from module.c addbuiltin)
Port of addbuiltin(Builtin b) from Src/module.c:409.
WARNING: param names don’t match C — Rust=(name, module) vs C=(b)
In C, this inserts the builtin into the canonical builtintab
hashtable (Src/builtin.c). The real builtin registration lives
in cmd.rs::BUILTINTAB and the routing fn here delegates to
the free addbuiltin (c:303 port) so the canonical BINF_ADDED
clash gate fires.
Returns 0 on success, 1 on clash (per C’s signature).
Sourcepub fn deletebuiltin(&mut self, name: &str, _module: &str) -> i32
pub fn deletebuiltin(&mut self, name: &str, _module: &str) -> i32
Unregister a builtin (from module.c deletebuiltin)
Port of deletebuiltin(const char *nam) from Src/module.c:449.
Returns 0 on success (entry found + removed from ledger), -1
on miss — matching the canonical free fn (00e6a9ce7e) and
C’s deletebuiltin return contract.
WARNING: param names don’t match C — Rust=(name, module) vs C=(nam)
Sourcepub fn add_autobin(&mut self, name: &str, module: &str, flags: i32) -> i32
pub fn add_autobin(&mut self, name: &str, module: &str, flags: i32) -> i32
Register autoloading builtin.
Port of static int add_autobin(const char *module, const char *bnam, int flags) from Src/module.c:426. C allocates a Builtin node
with optstr=module, sets BINF_AUTOALL if FEAT_AUTOALL is in
flags, then calls addbuiltin(bn). On failure, the freshly
allocated node is freed; success returns 0, conflict returns 1
unless FEAT_IGNORE masks it.
WARNING: param names don’t match C — Rust=(name, module, flags) vs C=(module, bnam, flags)
Sourcepub fn del_autobin(&mut self, name: &str, flags: i32) -> i32
pub fn del_autobin(&mut self, name: &str, flags: i32) -> i32
Port of static int del_autobin(const char *module, const char *bnam, int flags) from Src/module.c:464.
C body (c:464-478):
Builtin bn = (Builtin) builtintab->getnode2(builtintab, bnam);
if (!bn) { if(!(flags & FEAT_IGNORE)) return 2; }
else if (bn->node.flags & BINF_ADDED) {
if (!(flags & FEAT_IGNORE)) return 3;
} else deletebuiltin(bnam);
return 0;2 = “no such builtin”, 3 = “real registered builtin (BINF_ADDED) — can’t unload”, 0 = success (removed autoload entry). FEAT_IGNORE masks both error returns.
zshrs architecture: builtintab is static-linked at startup
(createbuiltintable() builds an immutable HashMap), so every
entry there is effectively BINF_ADDED. The autoload-only entries
live in self.autoload_builtins. The faithful mapping:
- if name is in
builtintab→ BINF_ADDED → return 3 (or 0 with FEAT_IGNORE). - else if name is in
autoload_builtins→ remove it, return 0. - else → not present → return 2 (or 0 with FEAT_IGNORE). WARNING: param names don’t match C — Rust=(name, flags) vs C=(module, bnam, flags)
Sourcepub fn setbuiltins(
&mut self,
module: &str,
names: &[&str],
e: Option<&[i32]>,
) -> i32
pub fn setbuiltins( &mut self, module: &str, names: &[&str], e: Option<&[i32]>, ) -> i32
Set/clear a slice of builtins per e[] mask.
Port of static int setbuiltins(char const *nam, Builtin binl, int size, int *e) from Src/module.c:501. For each Builtin in
binl[0..size]: if e[n] is set, add the builtin (skip if
already BINF_ADDED); else delete the builtin (skip if not
BINF_ADDED). Warnings on clash/already-deleted; returns 1 if
any op failed.
WARNING: param names don’t match C — Rust=(module, names, e) vs C=(nam, binl, size, e)
Sourcepub fn addconddef(&mut self, name: &str, module: &str) -> i32
pub fn addconddef(&mut self, name: &str, module: &str) -> i32
Register a condition (from module.c addconddef)
Port of addconddef(Conddef c) from Src/module.c:703.
WARNING: param names don’t match C — Rust=(name, module) vs C=(c)
Like addbuiltin, the real registration lives in
cond.rs::CONDTAB; the routing fn here delegates to the free
addconddef (4304-port) so the canonical name+infix-flag
clash gate fires.
Returns 0 on success, 1 on clash (matches C’s signature).
Sourcepub fn deleteconddef(&mut self, name: &str, _module: &str) -> i32
pub fn deleteconddef(&mut self, name: &str, _module: &str) -> i32
Unregister a condition (from module.c deleteconddef)
Port of deleteconddef(Conddef c) from Src/module.c:724.
Returns 0 on success (entry was found + removed), -1 on miss.
Mirrors C’s deleteconddef return contract.
WARNING: param names don’t match C — Rust=(name, module) vs C=(c)
Sourcepub fn getconddef(&self, name: &str) -> Option<&str>
pub fn getconddef(&self, name: &str) -> Option<&str>
Get condition definition (from module.c getconddef)
Port of getconddef(int inf, const char *name, int autol) from Src/module.c:648.
WARNING: param names don’t match C — Rust=(name) vs C=(inf, name, autol)
Returns the autoload mapping if any. C consults the canonical
condtab first; the autoload table is the fallback.
Sourcepub fn add_autocond(&mut self, name: &str, module: &str, flags: i32) -> i32
pub fn add_autocond(&mut self, name: &str, module: &str, flags: i32) -> i32
Register autoloading condition.
Port of static int add_autocond(const char *module, const char *cnam, int flags) from Src/module.c:792. C body allocates a
Conddef, copies name/module, sets CONDF_INFIX if
FEAT_INFIX and CONDF_AUTOALL if FEAT_AUTOALL, then calls
addconddef(c). On addconddef failure (already exists) the
node is freed; returns 1 unless FEAT_IGNORE.
WARNING: param names don’t match C — Rust=(name, module, flags) vs C=(module, cnam, flags)
Sourcepub fn del_autocond(&mut self, name: &str, flags: i32) -> i32
pub fn del_autocond(&mut self, name: &str, flags: i32) -> i32
Port of static int del_autocond(const char *modnam, const char *cnam, int flags) from Src/module.c:819.
C body (c:819-835):
Conddef cd = getconddef((flags & FEAT_INFIX) ? 1 : 0, cnam, 0);
if (!cd) { if (!(flags & FEAT_IGNORE)) return 2; }
else if (cd->flags & CONDF_ADDED) {
if (!(flags & FEAT_IGNORE)) return 3;
} else deleteconddef(cd);
return 0;2 = “no such condition”, 3 = “registered condition (CONDF_ADDED) — can’t unload”, 0 = success. FEAT_IGNORE masks both error returns. WARNING: param names don’t match C — Rust=(name, flags) vs C=(modnam, cnam, flags)
Sourcepub fn setparamdefs(
&mut self,
module: &str,
names: &[&str],
e: Option<&[i32]>,
) -> i32
pub fn setparamdefs( &mut self, module: &str, names: &[&str], e: Option<&[i32]>, ) -> i32
Add or remove sets of parameters; same shape as setbuiltins.
Port of static int setparamdefs(char const *nam, Paramdef d, int size, int *e) from Src/module.c:1170. For each Paramdef
in d[0..size]: if e[n] is set and d->pm is null, add the
param via addparamdef(d); if e[n] is clear and d->pm is
non-null, remove via deleteparamdef(d). Warnings on
error/already-deleted; returns 1 if any op failed.
WARNING: param names don’t match C — Rust=(module, names, e) vs C=(nam, d, size, e)
Sourcepub fn add_autoparam(&mut self, name: &str, module: &str, flags: i32) -> i32
pub fn add_autoparam(&mut self, name: &str, module: &str, flags: i32) -> i32
Register autoloading parameter.
Port of static int add_autoparam(const char *module, const char *pnam, int flags) from Src/module.c:1198. C body:
checkaddparam() clash check (returns 2 if -i’d), then
setsparam(pnam, module) creating the param with PM_AUTOLOAD
(+ PM_AUTOALL if FEAT_AUTOALL). queue_signals/noerrs=2
bracket so the setsparam doesn’t echo errors out.
WARNING: param names don’t match C — Rust=(name, module, flags) vs C=(module, pnam, flags)
Sourcepub fn del_autoparam(&mut self, name: &str, flags: i32) -> i32
pub fn del_autoparam(&mut self, name: &str, flags: i32) -> i32
Port of static int del_autoparam(const char *modnam, const char *pnam, int flags) from Src/module.c:1240.
C body (c:1240-1255):
Param pm = (Param) gethashnode2(paramtab, pnam);
if (!pm) { if (!(flags & FEAT_IGNORE)) return 2; }
else if (!(pm->node.flags & PM_AUTOLOAD)) {
if (!(flags & FEAT_IGNORE)) return 3;
} else unsetparam_pm(pm, 0, 1);
return 0;2 = “no such param”, 3 = “real param (not autoload) — can’t unload”, 0 = success. FEAT_IGNORE masks both error returns. WARNING: param names don’t match C — Rust=(name, flags) vs C=(modnam, pnam, flags)
Sourcepub fn enable_feature(&mut self, module: &str, _name: &str) -> bool
pub fn enable_feature(&mut self, module: &str, _name: &str) -> bool
Enable a feature (from module.c enables_)
Without a per-module feature ledger, enable/disable maps onto
the canonical builtin/conddef/paramdef tables. Returns true if
the module itself is registered. The actual per-feature
enabled-bit lives on the canonical record (e.g. Builtin.flags
BINF_DISABLED).
Sourcepub fn disable_feature(&mut self, module: &str, _name: &str) -> bool
pub fn disable_feature(&mut self, module: &str, _name: &str) -> bool
Disable a feature
Sourcepub fn list_features(&self, _module: &str) -> Vec<String>
pub fn list_features(&self, _module: &str) -> Vec<String>
List feature names of a module (from module.c features_).
Without a per-module ledger, this returns an empty list — C
computes feature names by walking the canonical tables for
entries that name the given module. Callers that care use
features_module/features_ directly.
Sourcepub fn module_linked(&self, name: &str) -> bool
pub fn module_linked(&self, name: &str) -> bool
Check if a module is linked (statically compiled) (from module.c module_linked)
Port of module_linked(char const *name) from Src/module.c:385.
Sourcepub fn resolve_autoload_builtin(&self, name: &str) -> Option<&str>
pub fn resolve_autoload_builtin(&self, name: &str) -> Option<&str>
Resolve autoload — find which module provides a builtin
Sourcepub fn resolve_autoload_param(&self, name: &str) -> Option<&str>
pub fn resolve_autoload_param(&self, name: &str) -> Option<&str>
Resolve autoload — find which module provides a parameter
Sourcepub fn ensurefeature(&mut self, module: &str, feature: &str) -> bool
pub fn ensurefeature(&mut self, module: &str, feature: &str) -> bool
Ensure a module’s feature is available
Port of ensurefeature(const char *modname, const char *prefix, const char *feature) from Src/module.c:3415.
WARNING: param names don’t match C — Rust=(module, feature) vs C=(modname, prefix, feature)
Trait Implementations§
Source§impl Debug for modulestab
impl Debug for modulestab
Source§impl Default for modulestab
impl Default for modulestab
Source§fn default() -> modulestab
fn default() -> modulestab
Auto Trait Implementations§
impl Freeze for modulestab
impl RefUnwindSafe for modulestab
impl Send for modulestab
impl Sync for modulestab
impl Unpin for modulestab
impl UnsafeUnpin for modulestab
impl UnwindSafe for modulestab
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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