interceptor

Attribute Macro interceptor 

Source
#[interceptor]
Expand description

Attribute macro for impl blocks to generate Protocol and Interceptor implementations.

This macro generates the trait implementations, delegating non-overridden methods to the next interceptor field (identified by #[next] in the struct).

Important: The struct must have #[derive(Interceptor)] with a #[next] field.

§Attributes

  • #[overrides] - Mark methods that provide custom implementations

§Examples

With custom logic:

#[derive(Interceptor)]
pub struct MyInterceptor<P: Interceptor> {
    #[next]
    next: P,  // Can use any field name
    buffer: VecDeque<TaggedPacket>,
}

#[interceptor]
impl<P: Interceptor> MyInterceptor<P> {
    #[overrides]
    fn handle_read(&mut self, msg: TaggedPacket) -> Result<(), Self::Error> {
        // Custom logic
        self.next.handle_read(msg)
    }
}

Pure delegation (no custom logic):

#[derive(Interceptor)]
pub struct PassthroughInterceptor<P: Interceptor> {
    #[next]
    wrapped: P,  // Can use any field name
}

#[interceptor]
impl<P: Interceptor> PassthroughInterceptor<P> {}
// Empty impl - all methods delegate to wrapped field