Struct relm::Relm
[−]
[src]
pub struct Relm<MSG: Clone + DisplayVariant> { /* fields omitted */ }
Handle connection of futures to send messages to the update()
and update_command()
methods.
Methods
impl<MSG: Clone + DisplayVariant + Send + 'static> Relm<MSG>
[src]
fn connect<CALLBACK, FAILCALLBACK, STREAM, TOSTREAM>(&self,
to_stream: TOSTREAM,
success_callback: CALLBACK,
failure_callback: FAILCALLBACK)
-> Box<Future<Item=(), Error=()>> where CALLBACK: Fn(STREAM::Item) -> MSG + 'static,
FAILCALLBACK: Fn(STREAM::Error) -> MSG + 'static,
STREAM: Stream + 'static,
TOSTREAM: ToStream<STREAM, Item=STREAM::Item, Error=STREAM::Error> + 'static
to_stream: TOSTREAM,
success_callback: CALLBACK,
failure_callback: FAILCALLBACK)
-> Box<Future<Item=(), Error=()>> where CALLBACK: Fn(STREAM::Item) -> MSG + 'static,
FAILCALLBACK: Fn(STREAM::Error) -> MSG + 'static,
STREAM: Stream + 'static,
TOSTREAM: ToStream<STREAM, Item=STREAM::Item, Error=STREAM::Error> + 'static
Connect a Future
or a Stream
called to_stream
to send the message success_callback
in case of success and failure_callback
in case of failure.
Note
This function does not spawn the future.
You'll usually want to use Relm::connect_exec()
to both connect and spawn the future.
Warning
This function must be executed of the tokio thread, i.e. in the
subscriptions()
or
update_command()
methods.
fn connect_ignore_err<CALLBACK, STREAM, TOSTREAM>(&self,
to_stream: TOSTREAM,
success_callback: CALLBACK)
-> Box<Future<Item=(), Error=()>> where CALLBACK: Fn(STREAM::Item) -> MSG + 'static,
STREAM: Stream + 'static,
TOSTREAM: ToStream<STREAM, Item=STREAM::Item, Error=STREAM::Error> + 'static
to_stream: TOSTREAM,
success_callback: CALLBACK)
-> Box<Future<Item=(), Error=()>> where CALLBACK: Fn(STREAM::Item) -> MSG + 'static,
STREAM: Stream + 'static,
TOSTREAM: ToStream<STREAM, Item=STREAM::Item, Error=STREAM::Error> + 'static
This function is the same as Relm::connect()
except it does not take a
failure_callback
; hence, it ignores the errors.
Warning
This function must be executed of the tokio thread, i.e. in the
subscriptions()
or
update_command()
methods.
fn connect_exec<CALLBACK, FAILCALLBACK, STREAM, TOSTREAM>(&self,
to_stream: TOSTREAM,
callback: CALLBACK,
failure_callback: FAILCALLBACK) where CALLBACK: Fn(STREAM::Item) -> MSG + 'static,
FAILCALLBACK: Fn(STREAM::Error) -> MSG + 'static,
STREAM: Stream + 'static,
TOSTREAM: ToStream<STREAM, Item=STREAM::Item, Error=STREAM::Error> + 'static
to_stream: TOSTREAM,
callback: CALLBACK,
failure_callback: FAILCALLBACK) where CALLBACK: Fn(STREAM::Item) -> MSG + 'static,
FAILCALLBACK: Fn(STREAM::Error) -> MSG + 'static,
STREAM: Stream + 'static,
TOSTREAM: ToStream<STREAM, Item=STREAM::Item, Error=STREAM::Error> + 'static
Connect the future to_stream
and spawn it on the tokio main loop.
Warning
This function must be executed of the tokio thread, i.e. in the
subscriptions()
or
update_command()
methods.
fn connect_exec_ignore_err<CALLBACK, STREAM, TOSTREAM>(&self,
to_stream: TOSTREAM,
callback: CALLBACK) where CALLBACK: Fn(STREAM::Item) -> MSG + 'static,
STREAM: Stream + 'static,
TOSTREAM: ToStream<STREAM, Item=STREAM::Item, Error=STREAM::Error> + 'static
to_stream: TOSTREAM,
callback: CALLBACK) where CALLBACK: Fn(STREAM::Item) -> MSG + 'static,
STREAM: Stream + 'static,
TOSTREAM: ToStream<STREAM, Item=STREAM::Item, Error=STREAM::Error> + 'static
Connect the future to_stream
and spawn it on the tokio main loop, ignoring any error.
Warning
This function must be executed of the tokio thread, i.e. in the
subscriptions()
or
update_command()
methods.
fn exec<FUTURE: Future<Item=(), Error=()> + 'static>(&self, future: FUTURE)
Spawn a future in the tokio event loop.
Warning
This function must be executed of the tokio thread, i.e. in the
subscriptions()
or
update_command()
methods.
fn handle(&self) -> &Handle
Get a handle to the tokio event loop.
fn run<WIDGET>() -> Result<(), ()> where WIDGET: Widget<MSG> + 'static, WIDGET::Model: Send
Create the specified relm Widget
and run the main event loops.
```
extern crate gtk;
#[macro_use]
extern crate relm;
#[macro_use]
extern crate relm_derive;
use gtk::{Window, WindowType};
use relm::{Relm, RemoteRelm, Widget};
#[derive(Clone)]
struct Win {
window: Window,
}
impl Widget for Win {
type Container = Window;
type Model = ();
fn container(&self) -> &Self::Container {
&self.window
}
fn model() -> () {
()
}
fn update(&mut self, event: Msg, model: &mut Self::Model) {
}
fn view(relm: RemoteRelm, _model: &Self::Model) -> Self {
let window = Window::new(WindowType::Toplevel);
Win {
window: window,
}
}
}
#[derive(Msg)]
enum Msg {}
fn main() {
}
fn run() {
/// Win
is a relm Widget
.
Relm::run::
}
fn stream(&self) -> &EventStream<MSG>
Get the event stream of the widget. This is used internally by the library.