Expand description
Derive macros for RTC Interceptor trait.
This crate provides two macros that work together:
#[derive(Interceptor)]- Marks a struct as an interceptor and identifies the next field#[interceptor]- Attribute macro for impl blocks to generate trait implementations
§Design Pattern
The design follows Rust’s derive pattern (similar to #[derive(Default)] with #[default]):
ⓘ
use rtc_interceptor::{Interceptor, interceptor, TaggedPacket, Packet, StreamInfo};
use std::collections::VecDeque;
#[derive(Interceptor)]
pub struct MyInterceptor<P: Interceptor> {
#[next]
next: P, // The next interceptor in the chain (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 here
self.next.handle_read(msg)
}
}§Pure Delegation (No Custom Logic)
For interceptors that just pass through without modification:
ⓘ
#[derive(Interceptor)]
pub struct PassthroughInterceptor<P: Interceptor> {
#[next]
next: P,
}
#[interceptor]
impl<P: Interceptor> PassthroughInterceptor<P> {}
// Empty impl block - all methods are auto-generated§Required Imports
The macros require certain types to be in scope:
ⓘ
use rtc_interceptor::{Interceptor, interceptor, TaggedPacket, Packet, StreamInfo};
// Or through rtc umbrella crate:
use rtc::interceptor::{Interceptor, interceptor, TaggedPacket, Packet, StreamInfo};
use rtc::shared::error::Error;
use rtc::sansio; // Required for macro-generated codeAttribute Macros§
- interceptor
- Attribute macro for impl blocks to generate Protocol and Interceptor implementations.
Derive Macros§
- Interceptor
- Derive macro that marks a struct as an interceptor.