Trait Handler

Source
pub trait Handler {
    // Required methods
    fn wrap_normal<Rust2DartCodec, PrepareFn, TaskFn>(
        &self,
        task_info: TaskInfo,
        prepare: PrepareFn,
    )
       where PrepareFn: FnOnce() -> TaskFn,
             TaskFn: FnOnce(TaskContext) -> Result<Rust2DartCodec::Message, Rust2DartCodec::Message> + Send + 'static,
             Rust2DartCodec: BaseCodec;
    fn wrap_sync<Rust2DartCodec, SyncTaskFn>(
        &self,
        task_info: TaskInfo,
        sync_task: SyncTaskFn,
    ) -> <Rust2DartCodec::Message as Rust2DartMessageTrait>::WireSyncRust2DartType
       where SyncTaskFn: FnOnce() -> Result<Rust2DartCodec::Message, Rust2DartCodec::Message>,
             Rust2DartCodec: BaseCodec;
    fn wrap_async<Rust2DartCodec, PrepareFn, TaskFn, TaskRetFut>(
        &self,
        task_info: TaskInfo,
        prepare: PrepareFn,
    )
       where PrepareFn: FnOnce() -> TaskFn,
             TaskFn: FnOnce(TaskContext) -> TaskRetFut + Send + 'static,
             TaskRetFut: Future<Output = Result<Rust2DartCodec::Message, Rust2DartCodec::Message>> + TaskRetFutTrait,
             Rust2DartCodec: BaseCodec;
    fn dart_fn_invoke(
        &self,
        dart_fn: DartOpaque,
        args: Vec<DartAbi>,
    ) -> DartFnFuture<Dart2RustMessageSse>;
    fn dart_fn_handle_output(&self, call_id: i32, message: Dart2RustMessageSse);
}
Expand description

Provide your own handler to customize how to execute your function calls, etc.

This API is not guaranteed to be stable following semver (since things are going to be added, and for every addition/change, it is a breaking change for this trait).

Required Methods§

Source

fn wrap_normal<Rust2DartCodec, PrepareFn, TaskFn>( &self, task_info: TaskInfo, prepare: PrepareFn, )
where PrepareFn: FnOnce() -> TaskFn, TaskFn: FnOnce(TaskContext) -> Result<Rust2DartCodec::Message, Rust2DartCodec::Message> + Send + 'static, Rust2DartCodec: BaseCodec,

Prepares the arguments, executes a Rust function and sets up its return value.

Why separate PrepareFn and TaskFn: because some things cannot be Send (e.g. raw pointers), so those can be done in PrepareFn, while the real work is done in TaskFn with Send.

The generated code depends on the fact that PrepareFn is synchronous to maintain correctness, therefore implementors of Handler must also uphold this property.

If a Rust function is marked sync, it must be called with wrap_sync instead.

Source

fn wrap_sync<Rust2DartCodec, SyncTaskFn>( &self, task_info: TaskInfo, sync_task: SyncTaskFn, ) -> <Rust2DartCodec::Message as Rust2DartMessageTrait>::WireSyncRust2DartType
where SyncTaskFn: FnOnce() -> Result<Rust2DartCodec::Message, Rust2DartCodec::Message>, Rust2DartCodec: BaseCodec,

Same as [wrap][Handler::wrap], but the Rust function will be called synchronously and need not implement Send.

Source

fn wrap_async<Rust2DartCodec, PrepareFn, TaskFn, TaskRetFut>( &self, task_info: TaskInfo, prepare: PrepareFn, )
where PrepareFn: FnOnce() -> TaskFn, TaskFn: FnOnce(TaskContext) -> TaskRetFut + Send + 'static, TaskRetFut: Future<Output = Result<Rust2DartCodec::Message, Rust2DartCodec::Message>> + TaskRetFutTrait, Rust2DartCodec: BaseCodec,

Same as [wrap][Handler::wrap], but for async Rust.

Source

fn dart_fn_invoke( &self, dart_fn: DartOpaque, args: Vec<DartAbi>, ) -> DartFnFuture<Dart2RustMessageSse>

Source

fn dart_fn_handle_output(&self, call_id: i32, message: Dart2RustMessageSse)

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§