From a0ce0a9da89a61606ac2f783bacf776965bae014 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Sommer?= Date: Fri, 31 Aug 2018 15:57:56 +0200 Subject: [PATCH] Update examples --- Cargo.toml | 3 ++- examples/hello_world.rs | 13 +++++-------- examples/hello_world_await.rs | 18 +++++++----------- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 071c2868..84b025dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,7 +31,8 @@ version = "0.2.1" [dev-dependencies] futures-await = { git = 'https://github.com/alexcrichton/futures-await' } -ruma-events = "0.9.0" +ruma-events = "0.10" +tokio-core = "0.1" [features] default = ["tls"] diff --git a/examples/hello_world.rs b/examples/hello_world.rs index 6039ee50..0667cc24 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -17,7 +17,7 @@ use ruma_client::api::r0; use ruma_events::EventType; use ruma_events::room::message::{MessageEventContent, MessageType, TextMessageEventContent}; use ruma_identifiers::RoomAliasId; -use tokio_core::reactor::{Core, Handle}; +use tokio_core::reactor::Core; use url::Url; // from https://stackoverflow.com/a/43992218/1592377 @@ -40,11 +40,10 @@ macro_rules! clone { } fn hello_world( - tokio_handle: &Handle, homeserver_url: Url, room: String, ) -> impl Future + 'static { - let client = Client::https(tokio_handle, homeserver_url, None).unwrap(); + let client = Client::https(homeserver_url, None).unwrap(); client.register_guest().and_then(clone!(client => move |_| { r0::alias::get_alias::call(client, r0::alias::get_alias::Request { @@ -79,9 +78,7 @@ fn main() { } }; - let mut core = Core::new().unwrap(); - let handle = core.handle(); - let server = Url::parse(&homeserver_url).unwrap(); - - core.run(hello_world(&handle, server, room)).unwrap(); + Core::new().unwrap() + .run(hello_world(homeserver_url.parse().unwrap(), room)) + .unwrap(); } diff --git a/examples/hello_world_await.rs b/examples/hello_world_await.rs index 16c81061..124c8283 100644 --- a/examples/hello_world_await.rs +++ b/examples/hello_world_await.rs @@ -1,5 +1,5 @@ #![feature(generators)] -#![feature(proc_macro)] +#![feature(proc_macro_non_items)] #![feature(try_from)] extern crate futures_await as futures; @@ -13,21 +13,20 @@ use std::convert::TryFrom; use std::env; use std::process::exit; -use futures::prelude::*; +use futures::prelude::{*, await}; use ruma_client::Client; use ruma_client::api::r0; use ruma_events::EventType; use ruma_events::room::message::{MessageEventContent, MessageType, TextMessageEventContent}; use ruma_identifiers::RoomAliasId; -use tokio_core::reactor::{Core, Handle}; +use tokio_core::reactor::Core; use url::Url; fn hello_world( - tokio_handle: &Handle, homeserver_url: Url, room: String, ) -> impl Future + 'static { - let client = Client::https(tokio_handle, homeserver_url, None).unwrap(); + let client = Client::https(homeserver_url, None).unwrap(); async_block! { await!(client.register_guest())?; @@ -75,10 +74,7 @@ fn main() { } }; - - let mut core = Core::new().unwrap(); - let handle = core.handle(); - let server = Url::parse(&homeserver_url).unwrap(); - - core.run(hello_world(&handle, server, room)).unwrap(); + Core::new().unwrap() + .run(hello_world(homeserver_url.parse().unwrap(), room)) + .unwrap(); }