summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-12-08 08:21:26 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-12-08 08:21:26 +0100
commit98160406f714728afe718f305bf9d12be1676b2d (patch)
treebf8fec3cb66bc478a021aba156d6be580586616e /core
parent9b84b6e40336543380312aa1b2b1091791ec25cd (diff)
downloadiced-98160406f714728afe718f305bf9d12be1676b2d.tar.gz
iced-98160406f714728afe718f305bf9d12be1676b2d.tar.bz2
iced-98160406f714728afe718f305bf9d12be1676b2d.zip
Allow listening to runtime events in subscriptions
Diffstat (limited to 'core')
-rw-r--r--core/src/subscription.rs42
1 files changed, 25 insertions, 17 deletions
diff --git a/core/src/subscription.rs b/core/src/subscription.rs
index 796982c7..4c021d75 100644
--- a/core/src/subscription.rs
+++ b/core/src/subscription.rs
@@ -1,51 +1,59 @@
//! Generate events asynchronously for you application.
/// An event subscription.
-pub struct Subscription<T> {
- handles: Vec<Box<dyn Handle<Output = T>>>,
+pub struct Subscription<I, O> {
+ connections: Vec<Box<dyn Connection<Input = I, Output = O>>>,
}
-impl<T> Subscription<T> {
+impl<I, O> Subscription<I, O> {
pub fn none() -> Self {
Self {
- handles: Vec::new(),
+ connections: Vec::new(),
}
}
- pub fn batch(subscriptions: impl Iterator<Item = Subscription<T>>) -> Self {
+ pub fn batch(
+ subscriptions: impl Iterator<Item = Subscription<I, O>>,
+ ) -> Self {
Self {
- handles: subscriptions
- .flat_map(|subscription| subscription.handles)
+ connections: subscriptions
+ .flat_map(|subscription| subscription.connections)
.collect(),
}
}
- pub fn handles(self) -> Vec<Box<dyn Handle<Output = T>>> {
- self.handles
+ pub fn connections(
+ self,
+ ) -> Vec<Box<dyn Connection<Input = I, Output = O>>> {
+ self.connections
}
}
-impl<T, A> From<A> for Subscription<T>
+impl<I, O, T> From<T> for Subscription<I, O>
where
- A: Handle<Output = T> + 'static,
+ T: Connection<Input = I, Output = O> + 'static,
{
- fn from(handle: A) -> Self {
+ fn from(handle: T) -> Self {
Self {
- handles: vec![Box::new(handle)],
+ connections: vec![Box::new(handle)],
}
}
}
-/// The handle of an event subscription.
-pub trait Handle {
+/// The connection of an event subscription.
+pub trait Connection {
+ type Input;
type Output;
fn id(&self) -> u64;
- fn stream(&self) -> futures::stream::BoxStream<'static, Self::Output>;
+ fn stream(
+ &self,
+ input: Self::Input,
+ ) -> futures::stream::BoxStream<'static, Self::Output>;
}
-impl<T> std::fmt::Debug for Subscription<T> {
+impl<I, O> std::fmt::Debug for Subscription<I, O> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Subscription").finish()
}