use super::queue::QueueEditGuard;
use crate::ircmsg::ClientMsg;
pub trait ClientMsgSink<'a> {
fn send(&mut self, msg: ClientMsg<'a>);
type Borrowed<'b>: ClientMsgSink<'a>
where
Self: 'b;
fn borrow_mut(&mut self) -> Self::Borrowed<'_>;
}
impl<'a, F: FnMut(ClientMsg<'a>)> ClientMsgSink<'a> for F {
fn send(&mut self, msg: ClientMsg<'a>) {
self(msg);
}
type Borrowed<'b> = &'b mut F where F: 'b;
fn borrow_mut(&mut self) -> Self::Borrowed<'_> {
self
}
}
impl<'a> ClientMsgSink<'static> for &mut QueueEditGuard<'a> {
fn send(&mut self, msg: ClientMsg<'static>) {
self.push(msg);
}
type Borrowed<'b> = &'b mut QueueEditGuard<'a> where Self: 'b;
fn borrow_mut(&mut self) -> Self::Borrowed<'_> {
self
}
}