Relax trait bounds on Replies methods

This commit is contained in:
Joscha 2023-01-20 17:16:09 +01:00
parent 6916977a47
commit ebb40edd0e

View file

@ -49,8 +49,7 @@ pub struct Replies<I, R> {
pending: HashMap<I, Sender<R>>, pending: HashMap<I, Sender<R>>,
} }
// TODO Relax bounds impl<I, R> Replies<I, R> {
impl<I: Eq + Hash, R> Replies<I, R> {
pub fn new(timeout: Duration) -> Self { pub fn new(timeout: Duration) -> Self {
Self { Self {
timeout, timeout,
@ -62,7 +61,10 @@ impl<I: Eq + Hash, R> Replies<I, R> {
self.timeout self.timeout
} }
pub fn wait_for(&mut self, id: I) -> PendingReply<R> { pub fn wait_for(&mut self, id: I) -> PendingReply<R>
where
I: Eq + Hash,
{
let (tx, rx) = oneshot::channel(); let (tx, rx) = oneshot::channel();
self.pending.insert(id, tx); self.pending.insert(id, tx);
PendingReply { PendingReply {
@ -71,7 +73,10 @@ impl<I: Eq + Hash, R> Replies<I, R> {
} }
} }
pub fn complete(&mut self, id: &I, result: R) { pub fn complete(&mut self, id: &I, result: R)
where
I: Eq + Hash,
{
if let Some(tx) = self.pending.remove(id) { if let Some(tx) = self.pending.remove(id) {
let _ = tx.send(result); let _ = tx.send(result);
} }