pub struct alias_table { /* private fields */ }Expand description
crate::ported::zsh_h::alias hash table
$aliastab alias hash.
Port of the aliastab HashTable from Src/hashtable.c —
bin_alias() (Src/builtin.c) drives every mutation. Suffix
aliases live in a separate sufaliastab instance.
NOT C-FAITHFUL — Rust-only typed wrapper. See WARNING on
cmdnam_table for the canonical-port direction.
Implementations§
Source§impl alias_table
impl alias_table
Sourcepub fn new() -> Self
pub fn new() -> Self
new — newhashtable(23, "aliastab", NULL) +
createaliastable(aliastab) (Src/hashtable.c:1210-1212),
without the two default aliases. sufaliastab is created at
hsize = 11 (Src/hashtable.c:1221) so sufaliastab_lock()
builds its table inline rather than going through here.
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
with_defaults — new() plus the two aliases
createaliastables() installs (Src/hashtable.c:1215-1216).
They are added FIRST, before any user alias, so the chain heads
come out in C’s order.
Sourcepub fn snapshot(&self) -> alias_table
pub fn snapshot(&self) -> alias_table
snapshot — the table as the parent had it, for a subshell to
hand back at its end.
C never needs this: getoutput and ( … ) fork
(Src/exec.c:4816, c:2880) and entersubsh (c:1123-1261)
leaves aliastab/sufaliastab alone, so the child mutates a
private copy that dies with it. zshrs runs both forms in process,
so the parent’s table is taken here and put back by restore.
O(1): the bucket array is CowArc-shared. The deep copy happens
only if the body adds, removes, disables or enables an alias.
Expanding one does not count — alias::inuse is atomic.
!!! RUST-ONLY METHOD — no C counterpart (C forks) !!!
Sourcepub fn restore(&mut self, snap: alias_table)
pub fn restore(&mut self, snap: alias_table)
restore — put back a table taken by snapshot, bucket order
and all (${(k)aliases} walks the buckets directly).
!!! RUST-ONLY METHOD — no C counterpart (C forks) !!!
Sourcepub fn add(&mut self, alias: alias) -> Option<alias>
pub fn add(&mut self, alias: alias) -> Option<alias>
add — addhashnode2 (Src/hashtable.c:168). C’s addnode
for this table is addhashnode (c:1194), which is
addhashnode2 + freenode(oldnode) (c:157-162); returning
the displaced node lets the caller do the freeing, and dropping
it is freealiasnode (c:1243).
Sourcepub fn get(&self, name: &str) -> Option<&alias>
pub fn get(&self, name: &str) -> Option<&alias>
get — gethashnode (Src/hashtable.c:245), i.e. the lookup
that skips DISABLED nodes (c:253).
Sourcepub fn get_including_disabled(&self, name: &str) -> Option<&alias>
pub fn get_including_disabled(&self, name: &str) -> Option<&alias>
get_including_disabled — gethashnode2
(Src/hashtable.c:255), the lookup WITHOUT the DISABLED filter.
Sourcepub fn get_mut(&mut self, name: &str) -> Option<&mut alias>
pub fn get_mut(&mut self, name: &str) -> Option<&mut alias>
get_mut — mutable gethashnode (Src/hashtable.c:245); C
mutates straight through the returned HashNode pointer.
Sourcepub fn remove(&mut self, name: &str) -> Option<alias>
pub fn remove(&mut self, name: &str) -> Option<alias>
remove — removehashnode (Src/hashtable.c:275).
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
clear — emptyhashtable (Src/hashtable.c:517), which is
resizehashtable(ht, ht->hsize): every node freed, hsize kept.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&String, &alias)>
pub fn iter(&self) -> impl Iterator<Item = (&String, &alias)>
iter — the unsorted scanmatchtable walk
(Src/hashtable.c:420-434): bucket 0..hsize-1, each chain
head→tail. This IS the order ${(k)aliases} / ${(k)galiases}
/ ${(k)saliases} emit via scanpmraliases and friends
(Src/Modules/parameter.c:2005-2047).
Sourcepub fn iter_sorted(&self) -> Vec<(&String, &alias)>
pub fn iter_sorted(&self) -> Vec<(&String, &alias)>
iter_sorted — the sorted arm of scanmatchtable
(Src/hashtable.c:395-401), which qsorts the collected nodes
with hnamcmp.
Trait Implementations§
Source§impl Debug for alias_table
impl Debug for alias_table
Auto Trait Implementations§
impl Freeze for alias_table
impl RefUnwindSafe for alias_table
impl Send for alias_table
impl Sync for alias_table
impl Unpin for alias_table
impl UnsafeUnpin for alias_table
impl UnwindSafe for alias_table
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