Skip to main content

EffectHandler

Trait EffectHandler 

Source
pub trait EffectHandler: Send + 'static {
    // Required methods
    fn handle_sync(
        &self,
        id: &str,
        request: &EffectRequest,
    ) -> Option<EffectResponse>;
    fn handle_async(
        &self,
        id: String,
        request: EffectRequest,
    ) -> Pin<Box<dyn Future<Output = EffectResponse> + Send>>;
    fn is_async(&self, request: &EffectRequest) -> bool;
}
Expand description

Handler for platform-specific side effects.

Native implementations use rfd (file dialogs), arboard (clipboard), and notify-rust (notifications). WASM implementations stub or use web platform APIs.

Handlers produce data (EffectResponse). The caller (App::execute) is responsible for emitting the response through the EventSink. This keeps handlers decoupled from the emission mechanism.

The Send + 'static bound is required because iced’s daemon holds the App across async boundaries and may move it between executor contexts on native (tokio). On wasm32, Send is trivially satisfied.

Required Methods§

Source

fn handle_sync( &self, id: &str, request: &EffectRequest, ) -> Option<EffectResponse>

Handle a synchronous effect. Returns Some(response) for effects that complete immediately (clipboard, notifications).

Returns None only if the request is completely unrecognized.

Source

fn handle_async( &self, id: String, request: EffectRequest, ) -> Pin<Box<dyn Future<Output = EffectResponse> + Send>>

Handle an async effect, returning a future that resolves to the response. Used for operations that must not block the event loop (file dialogs on native).

Source

fn is_async(&self, request: &EffectRequest) -> bool

Returns true if the given request should be handled async.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§