compo/component.rs
1use {
2 crate::runtime::{Cancellable, Runtime},
3 std::rc::{Rc, Weak},
4};
5
6pub trait Component<'a> {
7 fn new(rt: Weak<Runtime<'a, ()>>) -> Self;
8
9 fn get_rt(&self) -> Weak<Runtime<'a, ()>>;
10
11 fn spawn<Fut>(&self, fut: Fut) -> Cancellable
12 where
13 Fut: Future<Output=()> + 'a,
14 {
15 if let Some(rt) = self.get_rt().upgrade() {
16 rt.spawn(fut)
17 } else {
18 Default::default()
19 }
20 }
21
22 fn update(self: &Rc<Self>);
23}