2023-03-04 05:37:11 +01:00
|
|
|
use crate::futures::futures::{
|
2020-02-04 03:28:47 +01:00
|
|
|
channel::mpsc,
|
2020-01-19 10:17:08 +01:00
|
|
|
task::{Context, Poll},
|
|
|
|
|
Sink,
|
|
|
|
|
};
|
|
|
|
|
use std::pin::Pin;
|
|
|
|
|
|
2020-05-28 02:49:32 +02:00
|
|
|
/// An event loop proxy that implements `Sink`.
|
2020-05-21 00:37:47 +02:00
|
|
|
#[derive(Debug)]
|
2020-01-19 10:17:08 +01:00
|
|
|
pub struct Proxy<Message: 'static> {
|
|
|
|
|
raw: winit::event_loop::EventLoopProxy<Message>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<Message: 'static> Clone for Proxy<Message> {
|
|
|
|
|
fn clone(&self) -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
raw: self.raw.clone(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<Message: 'static> Proxy<Message> {
|
2020-05-28 02:49:32 +02:00
|
|
|
/// Creates a new [`Proxy`] from an `EventLoopProxy`.
|
2020-01-19 10:17:08 +01:00
|
|
|
pub fn new(raw: winit::event_loop::EventLoopProxy<Message>) -> Self {
|
|
|
|
|
Self { raw }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<Message: 'static> Sink<Message> for Proxy<Message> {
|
2020-02-04 03:28:47 +01:00
|
|
|
type Error = mpsc::SendError;
|
2020-01-19 10:17:08 +01:00
|
|
|
|
|
|
|
|
fn poll_ready(
|
|
|
|
|
self: Pin<&mut Self>,
|
|
|
|
|
_cx: &mut Context<'_>,
|
|
|
|
|
) -> Poll<Result<(), Self::Error>> {
|
|
|
|
|
Poll::Ready(Ok(()))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn start_send(
|
|
|
|
|
self: Pin<&mut Self>,
|
|
|
|
|
message: Message,
|
|
|
|
|
) -> Result<(), Self::Error> {
|
|
|
|
|
let _ = self.raw.send_event(message);
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn poll_flush(
|
|
|
|
|
self: Pin<&mut Self>,
|
|
|
|
|
_cx: &mut Context<'_>,
|
|
|
|
|
) -> Poll<Result<(), Self::Error>> {
|
|
|
|
|
Poll::Ready(Ok(()))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn poll_close(
|
|
|
|
|
self: Pin<&mut Self>,
|
|
|
|
|
_cx: &mut Context<'_>,
|
|
|
|
|
) -> Poll<Result<(), Self::Error>> {
|
|
|
|
|
Poll::Ready(Ok(()))
|
|
|
|
|
}
|
|
|
|
|
}
|