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 rtci_interceptor::{Interceptor, StreamInfo, TaggedPacket, interceptor};
use shared::error::Error; // the `rtci-shared` crate (`rtci::shared::error::Error`)
use std::collections::VecDeque;
// and the `sansio` crate as a dependency (or `use rtci::sansio;`)
#[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 generated code names Interceptor, TaggedPacket, StreamInfo, Error and the
sansio crate unqualified, so all five must be in scope where the macros are used:
ⓘ
use rtci_interceptor::{Interceptor, StreamInfo, TaggedPacket, interceptor};
use shared::error::Error; // `rtci-shared`, a dependency of its own
// `sansio` a dependency of its own
// Or through the rtci crate:
use rtci::interceptor::{Interceptor, StreamInfo, TaggedPacket, interceptor};
use rtci::sansio;
use rtci::shared::error::Error;(These examples are not compiled here: a procedural macro crate cannot use the crate
that re-exports it. rtci-interceptor’s GccInterceptor and jitter buffer are built
with them.)
Attribute 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.