Struct interchange::Interchange
source · pub struct Interchange<Rq, Rp, const N: usize> { /* private fields */ }
Expand description
Set of N
channels
Channels can be claimed with claim()
static interchange: Interchange<Request, Response,10> = Interchange::new();
for i in 0..10 {
let rq: Requester<'_, Request, Response>;
let rp: Responder<'_, Request, Response>;
(rq, rp) = interchange.claim().unwrap() ;
}
Implementations§
source§impl<Rq, Rp, const N: usize> Interchange<Rq, Rp, N>
impl<Rq, Rp, const N: usize> Interchange<Rq, Rp, N>
sourcepub fn claim(&self) -> Option<(Requester<'_, Rq, Rp>, Responder<'_, Rq, Rp>)>
pub fn claim(&self) -> Option<(Requester<'_, Rq, Rp>, Responder<'_, Rq, Rp>)>
Claim one of the channels of the interchange. Returns None if called more than N
times.
sourcepub const fn as_interchange_ref(&self) -> InterchangeRef<'_, Rq, Rp>
pub const fn as_interchange_ref(&self) -> InterchangeRef<'_, Rq, Rp>
Returns a reference to the interchange with the N
const-generic removed.
This can avoid the requirement to have const N: usize
everywhere
static INTERCHANGE_INNER: Interchange<Request, Response, 1> = Interchange::new();
// The size of the interchange is absent from the type
static INTERCHANGE: InterchangeRef<'static, Request, Response> = INTERCHANGE_INNER.as_interchange_ref();
let (mut rq, mut rp) = INTERCHANGE.claim().unwrap();