Crate xrl [−] [src]
xrl
is a Tokio based library to build clients for the Xi editor. The challenge with Xi RPC is
that endpoints are both client (sending requests/notifications) and server (handling incoming
requests/notifications).
#![allow(unused_variables)] extern crate futures; extern crate tokio_core; extern crate xrl; use futures::{future, Future, Stream}; use tokio_core::reactor::Core; use xrl::{spawn, Client, Frontend, FrontendBuilder, ScrollTo, ServerResult, Style, Update}; // Type that represent our client struct MyFrontend { client: Client, } // Implement how our client handles notifications and requests from the core. impl Frontend for MyFrontend { fn update(&mut self, update: Update) -> ServerResult<()> { println!("received `update` from Xi core:\n{:?}", update); // note that here, we could send requests/notifications // to the core here with `self.client` Box::new(future::ok(())) } fn scroll_to(&mut self, scroll_to: ScrollTo) -> ServerResult<()> { println!("received `scroll_to` from Xi core:\n{:?}", scroll_to); Box::new(future::ok(())) } fn set_style(&mut self, style: Style) -> ServerResult<()> { println!("received `set_style` from Xi core:\n{:?}", style); Box::new(future::ok(())) } } struct MyFrontendBuilder; impl FrontendBuilder<MyFrontend> for MyFrontendBuilder { fn build(self, client: Client) -> MyFrontend { MyFrontend { client: client } } } fn main() { let mut core = Core::new().unwrap(); let handle = core.handle(); // spawn Xi core let (mut client, core_stderr) = spawn("xi-core", MyFrontendBuilder {}, &handle); // start logging Xi core's stderr let log_core_errors = core_stderr .for_each(|msg| { println!("xi-core stderr: {}", msg); Ok(()) }) .map_err(|_| ()); core.handle().spawn(log_core_errors); // Send a request to open a new view, and print the result let open_new_view = client .new_view(None) .map(|view_name| println!("opened new view: {}", view_name)); core.run(open_new_view).unwrap(); }
Structs
Client |
A client to send notifications and request to the core |
CoreStderr |
A stream of Xi core stderr lines |
Line | |
Operation | |
ScrollTo | |
Style | |
StyleDef | |
Update |
Enums
ClientError | |
OperationType | |
ServerError |
Traits
Frontend |
The |
FrontendBuilder |
A builder for the type |
Functions
spawn |
Start Xi core, and return a client and a stream of Xi's stderr lines. |
Type Definitions
ClientResult |
A future returned by all the |
ServerResult |