Struct DispatchTable

Source
pub struct DispatchTable<K, P: ?Sized, R> { /* private fields */ }

Implementations§

Source§

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

Source

pub fn new() -> Self

Examples found in repository?
examples/dispatch.rs (line 13)
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}

Trait Implementations§

Source§

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

Source§

fn len(&self) -> usize

Source§

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

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

Source§

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

Source§

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

Auto Trait Implementations§

§

impl<K, P, R> Freeze for DispatchTable<K, P, R>
where P: ?Sized,

§

impl<K, P, R> !RefUnwindSafe for DispatchTable<K, P, R>

§

impl<K, P, R> Send for DispatchTable<K, P, R>
where K: Send, P: ?Sized,

§

impl<K, P, R> Sync for DispatchTable<K, P, R>
where K: Sync, P: ?Sized,

§

impl<K, P, R> Unpin for DispatchTable<K, P, R>
where K: Unpin, P: ?Sized,

§

impl<K, P, R> !UnwindSafe for DispatchTable<K, P, R>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.