EventSinkExt

Trait EventSinkExt 

Source
pub trait EventSinkExt<EVT: Send + Sync + 'static + ToOwned<Owned = EVT>> {
    type Error;

    // Required method
    fn on_event<'a, 'async_trait>(
        &'a self,
        event: Cow<'a, EVT>,
        source: Option<Arc<EventBox>>,
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'a: 'async_trait;
}
Expand description

If the event object implements ToOwned trait (note that all Clone object implements it), EventSink implementation can be simplified by implementing helper EventSinkExt with only one event handler accepting std::borrow::Cow parameter, instead of separate handlers for owned and borrowed cases

If structure implements EventSinkExt the EventSink trait can be derived for it:

use std::sync::Arc;
use async_trait::async_trait;
use std::borrow::Cow;
use async_event_streams::{EventBox, EventSink, EventSinkExt};
use async_event_streams_derive::EventSink;

#[derive(EventSink)]
#[event_sink(event=Event)]
struct Sink;

#[derive(Clone)]
struct Event;

#[async_trait]
impl EventSinkExt<Event> for Sink {
    type Error = ();
    async fn on_event<'a>(&'a self, event: Cow<'a, Event>, source: Option<Arc<EventBox>>) -> Result<(), Self::Error> {
        todo!()
    }
}

Required Associated Types§

Required Methods§

Source

fn on_event<'a, 'async_trait>( &'a self, event: Cow<'a, EVT>, source: Option<Arc<EventBox>>, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'a: 'async_trait,

Implementors§