pub struct Registry<P> { /* private fields */ }Expand description
Registry for constructing interceptor chains.
Registry wraps an interceptor chain and allows adding more interceptors
via the with method. The chain can be extracted with build.
§Example
use rtc_interceptor::{ReceiverReportBuilder, Registry, SenderReportBuilder};
// Each `with` changes the registry's type, so rebind rather than reassign.
let registry = Registry::new()
.with(SenderReportBuilder::new().build())
.with(ReceiverReportBuilder::new().build());
// Build the final chain
let chain = registry.build();§Helper Function Pattern
use rtc_interceptor::{Interceptor, ReceiverReportBuilder, Registry, SenderReportBuilder};
fn register_default_interceptors<P: Interceptor>(
registry: Registry<P>,
) -> Registry<impl Interceptor + use<P>> {
registry
.with(SenderReportBuilder::new().build())
.with(ReceiverReportBuilder::new().build())
}
let registry = Registry::new();
let registry = register_default_interceptors(registry);
let chain = registry.build();Implementations§
Source§impl<P: Interceptor> Registry<P>
impl<P: Interceptor> Registry<P>
Sourcepub fn from(inner: P) -> Self
pub fn from(inner: P) -> Self
Create a registry from an existing interceptor.
§Example
use rtc_interceptor::{NoopInterceptor, Registry};
let custom = NoopInterceptor::new();
let registry = Registry::from(custom);Sourcepub fn with<O, F>(self, f: F) -> Registry<O>where
F: FnOnce(P) -> O,
O: Interceptor,
pub fn with<O, F>(self, f: F) -> Registry<O>where
F: FnOnce(P) -> O,
O: Interceptor,
Wrap the current chain with another interceptor.
Returns a new Registry with the updated chain type.
§Example
use rtc_interceptor::{ReceiverReportBuilder, Registry, SenderReportBuilder};
let registry = Registry::new()
.with(SenderReportBuilder::new().build())
.with(ReceiverReportBuilder::new().build());Sourcepub fn build(self) -> P
pub fn build(self) -> P
Build and return the interceptor chain.
Consumes the registry and returns the inner interceptor chain.
§Example
use rtc_interceptor::{Registry, SenderReportBuilder};
let registry = Registry::new().with(SenderReportBuilder::new().build());
let chain = registry.build();Sourcepub fn boxed(self) -> Registry<BoxedInterceptor>where
P: 'static,
pub fn boxed(self) -> Registry<BoxedInterceptor>where
P: 'static,
Erase the chain’s type, turning this into a Registry<BoxedInterceptor>.
The chain an application assembles at runtime is a deep nest of generic types
(TwccSender<NackResponder<...<NoopInterceptor>>>), which otherwise leaks into every
type that holds the peer connection. Boxing it collapses that to one concrete type, so
a struct can store an RTCPeerConnection<BoxedInterceptor> field directly.
§Example
use rtc_interceptor::{BoxedInterceptor, Registry, SenderReportBuilder};
// Whatever the chain was composed of, the result has one concrete type.
let chain: BoxedInterceptor = Registry::new()
.with(SenderReportBuilder::new().build())
.boxed()
.build();The rtc crate accepts the erased registry directly, so a peer connection can be stored
as RTCPeerConnection<BoxedInterceptor>:
let registry = register_default_interceptors(Registry::new(), &mut media_engine)?;
let pc = RTCPeerConnectionBuilder::new()
.with_interceptor_registry(registry.boxed())
.build()?;P: 'static is required because BoxedInterceptor is Box<dyn Interceptor + 'static>,
so the chain must not borrow anything shorter-lived. This is the only operation that needs
the bound, which is why Interceptor itself does not require 'static.