Interceptor

Derive Macro Interceptor 

Source
#[derive(Interceptor)]
{
    // Attributes available to this derive:
    #[next]
}
Expand description

Derive macro that marks a struct as an interceptor.

This macro validates the struct has a #[next] field and generates a hidden accessor method. It does NOT generate Protocol/Interceptor implementations - those are generated by the #[interceptor] attribute on the impl block.

§Attributes

  • #[next] - Mark the field that contains the next interceptor in the chain (required)

§Examples

Pure delegation (no custom logic):

#[derive(Interceptor)]
pub struct PassthroughInterceptor<P: Interceptor> {
    #[next]
    next: P,
}

#[interceptor]
impl<P: Interceptor> PassthroughInterceptor<P> {}

With custom logic:

#[derive(Interceptor)]
pub struct MyInterceptor<P: Interceptor> {
    #[next]
    next: P,
    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)
    }
}