experimental_reactive/
reactive.rs

1use std::ops::Deref;
2
3pub use self::SourceError::*;
4pub use self::SlotError::*;
5
6#[derive(PartialOrd, Ord, PartialEq, Eq, Debug)]
7pub enum SourceError {
8	Empty
9}
10
11#[derive(PartialOrd, Ord, PartialEq, Eq, Debug)]
12pub enum SlotError<T> {
13	Full(T),
14	SomeFull,
15}
16
17pub trait Sink<T, S>: Sized where S: Source<T> {
18	type Connected;
19	fn connect_source(self, src: S) -> Self::Connected;
20}
21
22pub trait Source<T> {
23	fn pull(&self) -> Result<T, SourceError>;
24}
25
26pub trait Signal<T, S>: Sized where S: Slot<T> {
27	type Connected;
28	fn connect_slot(self, slot: S) -> Self::Connected;
29}
30
31pub trait Slot<T> {
32	fn push(&self, T) -> Result<(), SlotError<T>>;
33}
34
35
36//--------------------------------------------------------------//
37
38impl<T, S, U> Slot<T> for S where S: Deref<Target=U>, U: Slot<T> {
39	fn push(&self, value: T) -> Result<(), SlotError<T>> { self.deref().push(value) }
40}
41
42impl<T, S, U> Source<T> for S where S: Deref<Target=U>, U: Source<T> {
43	fn pull(&self) -> Result<T, SourceError> { self.deref().pull() }
44}
45
46//--------------------------------------------------------------//