Make iced_native subscription input opaque
This commit is contained in:
parent
ba06d458d3
commit
293314405f
4 changed files with 36 additions and 28 deletions
|
|
@ -155,13 +155,13 @@ mod time {
|
||||||
|
|
||||||
struct Every(std::time::Duration);
|
struct Every(std::time::Duration);
|
||||||
|
|
||||||
impl<Hasher, Input> iced_native::subscription::Recipe<Hasher, Input> for Every
|
impl<H, I> iced_native::subscription::Recipe<H, I> for Every
|
||||||
where
|
where
|
||||||
Hasher: std::hash::Hasher,
|
H: std::hash::Hasher,
|
||||||
{
|
{
|
||||||
type Output = std::time::Instant;
|
type Output = std::time::Instant;
|
||||||
|
|
||||||
fn hash(&self, state: &mut Hasher) {
|
fn hash(&self, state: &mut H) {
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
|
|
||||||
std::any::TypeId::of::<Self>().hash(state);
|
std::any::TypeId::of::<Self>().hash(state);
|
||||||
|
|
@ -170,7 +170,7 @@ mod time {
|
||||||
|
|
||||||
fn stream(
|
fn stream(
|
||||||
self: Box<Self>,
|
self: Box<Self>,
|
||||||
_input: Input,
|
_input: I,
|
||||||
) -> futures::stream::BoxStream<'static, Self::Output> {
|
) -> futures::stream::BoxStream<'static, Self::Output> {
|
||||||
use futures::stream::StreamExt;
|
use futures::stream::StreamExt;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,16 @@
|
||||||
use crate::{Event, Hasher};
|
use crate::{Event, Hasher};
|
||||||
|
use futures::stream::BoxStream;
|
||||||
|
|
||||||
pub type Subscription<T> = iced_core::Subscription<Hasher, Input, T>;
|
pub type EventStream = BoxStream<'static, Event>;
|
||||||
pub type Input = futures::channel::mpsc::Receiver<Event>;
|
|
||||||
|
pub type Subscription<T> = iced_core::Subscription<Hasher, EventStream, T>;
|
||||||
|
|
||||||
pub use iced_core::subscription::Recipe;
|
pub use iced_core::subscription::Recipe;
|
||||||
|
|
||||||
|
mod events;
|
||||||
|
|
||||||
|
use events::Events;
|
||||||
|
|
||||||
pub fn events() -> Subscription<Event> {
|
pub fn events() -> Subscription<Event> {
|
||||||
Subscription::from_recipe(Events)
|
Subscription::from_recipe(Events)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Events;
|
|
||||||
|
|
||||||
impl Recipe<Hasher, Input> for Events {
|
|
||||||
type Output = Event;
|
|
||||||
|
|
||||||
fn hash(&self, state: &mut Hasher) {
|
|
||||||
use std::hash::Hash;
|
|
||||||
|
|
||||||
std::any::TypeId::of::<Self>().hash(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn stream(
|
|
||||||
self: Box<Self>,
|
|
||||||
input: Input,
|
|
||||||
) -> futures::stream::BoxStream<'static, Self::Output> {
|
|
||||||
use futures::StreamExt;
|
|
||||||
|
|
||||||
input.boxed()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
23
native/src/subscription/events.rs
Normal file
23
native/src/subscription/events.rs
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
use crate::{
|
||||||
|
subscription::{EventStream, Recipe},
|
||||||
|
Event, Hasher,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub struct Events;
|
||||||
|
|
||||||
|
impl Recipe<Hasher, EventStream> for Events {
|
||||||
|
type Output = Event;
|
||||||
|
|
||||||
|
fn hash(&self, state: &mut Hasher) {
|
||||||
|
use std::hash::Hash;
|
||||||
|
|
||||||
|
std::any::TypeId::of::<Self>().hash(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn stream(
|
||||||
|
self: Box<Self>,
|
||||||
|
event_stream: EventStream,
|
||||||
|
) -> futures::stream::BoxStream<'static, Self::Output> {
|
||||||
|
event_stream
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -468,7 +468,7 @@ impl Subscriptions {
|
||||||
let (event_sender, event_receiver) =
|
let (event_sender, event_receiver) =
|
||||||
futures::channel::mpsc::channel(100);
|
futures::channel::mpsc::channel(100);
|
||||||
|
|
||||||
let stream = recipe.stream(event_receiver);
|
let stream = recipe.stream(event_receiver.boxed());
|
||||||
let proxy = proxy.clone();
|
let proxy = proxy.clone();
|
||||||
|
|
||||||
let future = futures::future::select(
|
let future = futures::future::select(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue