pub struct MultiFn {
pub name: Arc<str>,
pub dispatch_fn: Value,
pub methods: Mutex<HashMap<String, Value>>,
pub dispatch_vals: Mutex<HashMap<String, Value>>,
pub prefers: Mutex<HashMap<String, Vec<String>>>,
pub preference_vals: Mutex<HashMap<String, Value>>,
pub default_dispatch: String,
/* private fields */
}Expand description
A Clojure multimethod — arbitrary dispatch via a user-supplied function.
Fields§
§name: Arc<str>§dispatch_fn: Value§methods: Mutex<HashMap<String, Value>>pr_str(dispatch-val) → implementation fn
dispatch_vals: Mutex<HashMap<String, Value>>pr_str(dispatch-val) → the dispatch value itself, for isa? lookups
prefers: Mutex<HashMap<String, Vec<String>>>recorded preferences: pr_str(preferred) → pr_str(over)
preference_vals: Mutex<HashMap<String, Value>>pr_str(preference dispatch value) → original value, including values which do not currently have a method.
default_dispatch: Stringnormally “:default”
Implementations§
Source§impl MultiFn
impl MultiFn
pub fn new(name: Arc<str>, dispatch_fn: Value, default_dispatch: String) -> Self
Sourcepub fn method_generation(&self) -> u64
pub fn method_generation(&self) -> u64
Current generation of this multimethod’s method and preference tables.
Sourcepub fn bump_method_generation(&self)
pub fn bump_method_generation(&self)
Invalidate this multimethod’s cached inherited/default resolutions.
Sourcepub fn cached_method(
&self,
dispatch_key: &str,
hierarchy_generation: u64,
method_generation: u64,
) -> Option<String>
pub fn cached_method( &self, dispatch_key: &str, hierarchy_generation: u64, method_generation: u64, ) -> Option<String>
Return a cached resolved method key when both source generations match. Observing either new generation lazily discards stale entries at once.
Sourcepub fn cache_method(
&self,
dispatch_key: String,
method_key: String,
hierarchy_generation: u64,
method_generation: u64,
)
pub fn cache_method( &self, dispatch_key: String, method_key: String, hierarchy_generation: u64, method_generation: u64, )
Cache dispatch_key -> method_key under the source generations used to
resolve it. A concurrent mutation makes the entry stale, so the next
lookup discards it; the write itself never needs to be suppressed.
Sourcepub fn cached_method_count(&self) -> usize
pub fn cached_method_count(&self) -> usize
Number of entries in the current cache, exposed for regression tests.