Skip to main content

ItemListenerSet

Struct ItemListenerSet 

Source
pub struct ItemListenerSet<I, O> { /* private fields */ }
Expand description

A bounded, ordered registration of the M3 item listener families.

use std::sync::Arc;

use oxide_batch::{
    BoxFuture, ItemListenerContext, ItemListenerSet, ListenerError, ReadListener,
};

struct AuditReads;

impl ReadListener<u32> for AuditReads {
    fn after_read<'a>(
        &'a self,
        item: &'a u32,
        _context: ItemListenerContext<'a>,
    ) -> BoxFuture<'a, Result<(), ListenerError>> {
        let accepted = *item < 1_000;
        Box::pin(async move {
            if accepted {
                Ok(())
            } else {
                Err(ListenerError::new())
            }
        })
    }
}

let listeners = ItemListenerSet::<u32, String>::new()
    .with_read_listener(Arc::new(AuditReads))?;
assert_eq!(listeners.read_listeners(), 1);

Implementations§

Source§

impl<I, O> ItemListenerSet<I, O>

Source

pub const MAX_LISTENERS: usize = MAX_LISTENERS

The largest accepted number of listeners in one family.

Source

pub fn new() -> Self

Constructs an empty registration.

Source

pub fn with_read_listener( self, listener: Arc<dyn ReadListener<I>>, ) -> Result<Self, ItemListenerError>

Registers one read listener.

§Errors

Returns ItemListenerError::TooManyListeners beyond the bound.

Source

pub fn with_process_listener( self, listener: Arc<dyn ProcessListener<I, O>>, ) -> Result<Self, ItemListenerError>

Registers one process listener.

§Errors

Returns ItemListenerError::TooManyListeners beyond the bound.

Source

pub fn with_write_listener( self, listener: Arc<dyn WriteListener<O>>, ) -> Result<Self, ItemListenerError>

Registers one write listener.

§Errors

Returns ItemListenerError::TooManyListeners beyond the bound.

Source

pub fn with_retry_listener( self, listener: Arc<dyn RetryListener>, ) -> Result<Self, ItemListenerError>

Registers one retry listener.

§Errors

Returns ItemListenerError::TooManyListeners beyond the bound.

Source

pub fn with_skip_listener( self, listener: Arc<dyn SkipListener<I, O>>, ) -> Result<Self, ItemListenerError>

Registers one skip listener.

§Errors

Returns ItemListenerError::TooManyListeners beyond the bound.

Source

pub fn is_empty(&self) -> bool

Returns whether no listener is registered.

Source

pub fn read_listeners(&self) -> usize

Returns the number of registered read listeners.

Source

pub fn process_listeners(&self) -> usize

Returns the number of registered process listeners.

Source

pub fn write_listeners(&self) -> usize

Returns the number of registered write listeners.

Source

pub fn retry_listeners(&self) -> usize

Returns the number of registered retry listeners.

Source

pub fn skip_listeners(&self) -> usize

Returns the number of registered skip listeners.

Source§

impl<I, O> ItemListenerSet<I, O>
where I: Sync, O: Sync,

The callback passes borrow items across await, so both item types must be shareable. Registration and inspection remain available for any item type.

Source

pub async fn before_read( &self, context: ItemListenerContext<'_>, ) -> BeforeCallbackOutcome

Runs read before-callbacks in registration order.

Source

pub async fn after_read( &self, entered: usize, item: &I, context: ItemListenerContext<'_>, ) -> Vec<ItemListenerFailure>

Runs read after-callbacks for entered listeners in reverse order.

Source

pub async fn on_read_error( &self, entered: usize, fault: FaultDescriptor, context: ItemListenerContext<'_>, ) -> Vec<ItemListenerFailure>

Runs read error callbacks for entered listeners in reverse order.

Source

pub async fn before_process( &self, input: &I, context: ItemListenerContext<'_>, ) -> BeforeCallbackOutcome

Runs process before-callbacks in registration order.

Source

pub async fn after_process( &self, entered: usize, input: &I, output: Option<&O>, context: ItemListenerContext<'_>, ) -> Vec<ItemListenerFailure>

Runs process after-callbacks for entered listeners in reverse order.

Source

pub async fn on_process_error( &self, entered: usize, input: &I, fault: FaultDescriptor, context: ItemListenerContext<'_>, ) -> Vec<ItemListenerFailure>

Runs process error callbacks for entered listeners in reverse order.

Source

pub async fn before_write( &self, outputs: &[O], context: ItemListenerContext<'_>, ) -> BeforeCallbackOutcome

Runs write before-callbacks in registration order.

Source

pub async fn after_write( &self, entered: usize, outputs: &[O], context: ItemListenerContext<'_>, ) -> Vec<ItemListenerFailure>

Runs write after-callbacks for entered listeners in reverse order.

Source

pub async fn on_write_error( &self, entered: usize, outputs: &[O], fault: FaultDescriptor, context: ItemListenerContext<'_>, ) -> Vec<ItemListenerFailure>

Runs write error callbacks for entered listeners in reverse order.

Source

pub async fn before_retry( &self, fault: FaultDescriptor, context: ItemListenerContext<'_>, ) -> BeforeCallbackOutcome

Runs retry before-callbacks in registration order.

Source

pub async fn after_retry( &self, entered: usize, fault: FaultDescriptor, outcome: RetryOutcome, context: ItemListenerContext<'_>, ) -> Vec<ItemListenerFailure>

Runs retry completion callbacks for entered listeners in reverse order.

Source

pub async fn on_retry_exhausted( &self, entered: usize, fault: FaultDescriptor, context: ItemListenerContext<'_>, ) -> Vec<ItemListenerFailure>

Runs retry exhaustion callbacks for entered listeners in reverse order.

Source

pub async fn on_skip_in_read( &self, fault: FaultDescriptor, context: ItemListenerContext<'_>, ) -> Vec<ItemListenerFailure>

Confirms a skipped read in registration order.

Source

pub async fn on_skip_in_process( &self, input: &I, fault: FaultDescriptor, context: ItemListenerContext<'_>, ) -> Vec<ItemListenerFailure>

Confirms a skipped input in registration order.

Source

pub async fn on_skip_in_write( &self, output: &O, fault: FaultDescriptor, context: ItemListenerContext<'_>, ) -> Vec<ItemListenerFailure>

Confirms a skipped output in registration order.

Trait Implementations§

Source§

impl<I, O> Clone for ItemListenerSet<I, O>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<I, O> Debug for ItemListenerSet<I, O>

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<I, O> Default for ItemListenerSet<I, O>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<I, O> !RefUnwindSafe for ItemListenerSet<I, O>

§

impl<I, O> !UnwindSafe for ItemListenerSet<I, O>

§

impl<I, O> Freeze for ItemListenerSet<I, O>

§

impl<I, O> Send for ItemListenerSet<I, O>

§

impl<I, O> Sync for ItemListenerSet<I, O>

§

impl<I, O> Unpin for ItemListenerSet<I, O>

§

impl<I, O> UnsafeUnpin for ItemListenerSet<I, O>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more