Skip to main content

IntoDispatcher

Trait IntoDispatcher 

Source
pub trait IntoDispatcher<Args, Ret, M> {
    type Target;
    type Output: BorrowMut<Self::Target>;

    // Required method
    fn into_dispatcher(self) -> Self::Output;
}
Expand description

Convert a dispatcher, a callback, or a tuple of them, into a Dispatcher for the argument tuple Args and result Ret; the traversals take any of these inputs.

  • An owned D or a borrowed &mut D keeps D as the Target, and must have exactly that signature.
  • A callback takes a leading prefix of one to four of the arguments, and its first parameter selects what it matches, as for a #[dispatch] handler: an FFI value, a borrowed object node or AnyView, or a typed MutationView for mutation. It is passed by value, & or &mut.
  • A tuple, possibly nested, tries its links in order. Only an outer None moves on to the next link; an error or an inner None stops.

M marks the input form and is inferred; when calling into_dispatcher directly, give Args and Ret. See also #[dispatch].

use tvm_ffi::{Any, AnyView, Dispatcher, IntoDispatcher, Result};
let callbacks = (|value: i64| Any::from(value + 1), |_value: AnyView<'_>| Any::new());
let mut dispatcher = IntoDispatcher::<(AnyView<'_>,), Option<Result<Any>>, _>::into_dispatcher(callbacks);
let result: Option<Result<Any>> = dispatcher.dispatch_tuple((AnyView::from(&41_i64),));
let result = result.unwrap()?;
assert_eq!(i64::try_from(result)?, 42);

Required Associated Types§

Source

type Target

Actual dispatcher type, independent of its owned or borrowed storage.

Source

type Output: BorrowMut<Self::Target>

Storage normalized once at entry, retaining the target’s identity.

Required Methods§

Source

fn into_dispatcher(self) -> Self::Output

Convert the input, once, before the traversal starts.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§