Trait Dispatch

Source
pub trait Dispatch<K, P: ?Sized, R>
where K: Eq + Hash,
{ // Required methods fn into_vec(self) -> Vec<(K, Box<dyn DispatchFunction<P, R>>)>; fn remove<Q>(&mut self, key: &Q) where K: Borrow<Q>, Q: Eq + Hash + ?Sized; fn insert(&mut self, key: K, item: Box<dyn DispatchFunction<P, R>>); fn contains_key<Q>(&self, key: &Q) -> bool where K: Borrow<Q>, Q: Eq + Hash + ?Sized; fn get<Q>(&self, key: &Q) -> Option<&Box<dyn DispatchFunction<P, R>>> where K: Borrow<Q>, Q: Eq + Hash + ?Sized; fn len(&self) -> usize; // Provided method fn call<Q>(&self, key: &Q, params: &P) -> Option<R> where K: Borrow<Q>, Q: Eq + Hash + ?Sized { ... } }

Required Methods§

Source

fn into_vec(self) -> Vec<(K, Box<dyn DispatchFunction<P, R>>)>

Source

fn remove<Q>(&mut self, key: &Q)
where K: Borrow<Q>, Q: Eq + Hash + ?Sized,

Source

fn insert(&mut self, key: K, item: Box<dyn DispatchFunction<P, R>>)

Source

fn contains_key<Q>(&self, key: &Q) -> bool
where K: Borrow<Q>, Q: Eq + Hash + ?Sized,

Source

fn get<Q>(&self, key: &Q) -> Option<&Box<dyn DispatchFunction<P, R>>>
where K: Borrow<Q>, Q: Eq + Hash + ?Sized,

Source

fn len(&self) -> usize

Provided Methods§

Source

fn call<Q>(&self, key: &Q, params: &P) -> Option<R>
where K: Borrow<Q>, Q: Eq + Hash + ?Sized,

Examples found in repository?
examples/dispatch.rs (line 17)
12fn main() {
13    let mut table = DispatchTable::new();
14    table.insert("add", Box::new(add));
15    table.insert("sub", Box::new(sub));
16
17    assert_eq!(table.call(&"add", &(1, 2)), Some(3));
18    assert_eq!(table.call(&"sub", &(5, 2)), Some(3));
19}

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<K, P: ?Sized, R> Dispatcher<K, P, R> for DispatchTable<K, P, R>
where K: Hash + Eq,