diff options
author | 2020-01-19 10:17:08 +0100 | |
---|---|---|
committer | 2020-01-19 10:17:44 +0100 | |
commit | b5b17ed4d800c03beb3ad535d1069a7784e8dc1d (patch) | |
tree | b9e6477bd11bd6784f8ee61e818b5f5ff1a44318 /winit/src/proxy.rs | |
parent | d50ff9b5d97d9c3d6c6c70a9b4efe764b6126c86 (diff) | |
download | iced-b5b17ed4d800c03beb3ad535d1069a7784e8dc1d.tar.gz iced-b5b17ed4d800c03beb3ad535d1069a7784e8dc1d.tar.bz2 iced-b5b17ed4d800c03beb3ad535d1069a7784e8dc1d.zip |
Create `iced_futures` and wire everything up
Diffstat (limited to '')
-rw-r--r-- | winit/src/proxy.rs | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/winit/src/proxy.rs b/winit/src/proxy.rs new file mode 100644 index 00000000..7e8dee98 --- /dev/null +++ b/winit/src/proxy.rs @@ -0,0 +1,57 @@ +use futures::{ + task::{Context, Poll}, + Sink, +}; +use std::pin::Pin; + +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> { + pub fn new(raw: winit::event_loop::EventLoopProxy<Message>) -> Self { + Self { raw } + } +} + +impl<Message: 'static> Sink<Message> for Proxy<Message> { + type Error = core::convert::Infallible; + + 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(())) + } +} |