From 5dbfa99d0b01cc9aa955b5fc3b9baab70ad595b3 Mon Sep 17 00:00:00 2001 From: Tim Kuehn Date: Mon, 26 Dec 2016 16:02:44 -0500 Subject: [PATCH] Shuffle around the sync/future modules --- examples/readme_expanded.rs | 4 ++-- src/client.rs | 2 +- src/lib.rs | 26 +++++++++++++++++--------- src/macros.rs | 4 ++-- src/server.rs | 3 ++- 5 files changed, 24 insertions(+), 15 deletions(-) diff --git a/examples/readme_expanded.rs b/examples/readme_expanded.rs index 9beeb5f..52c2027 100644 --- a/examples/readme_expanded.rs +++ b/examples/readme_expanded.rs @@ -33,7 +33,7 @@ struct HelloServer; impl HelloServer { fn listen(addr: SocketAddr) -> impl Future { let (tx, rx) = futures::oneshot(); - tarpc::REMOTE.spawn(move |handle| { + tarpc::future::REMOTE.spawn(move |handle| { Ok(tx.complete(tarpc::listen_with(addr, move || Ok(HelloServer), handle.clone()))) }); rx.map_err(|e| panic!(e)).and_then(|result| result) @@ -57,7 +57,7 @@ pub struct FutureClient(tarpc::Client); impl FutureClient { fn connect(addr: &SocketAddr) -> impl Future { - tarpc::Client::connect_remotely(addr, &tarpc::REMOTE).map(FutureClient) + tarpc::Client::connect_remotely(addr, &tarpc::future::REMOTE).map(FutureClient) } pub fn hello(&mut self, name: String) diff --git a/src/client.rs b/src/client.rs index 16871c6..391e69c 100644 --- a/src/client.rs +++ b/src/client.rs @@ -94,7 +94,7 @@ impl fmt::Debug for Client /// Exposes a trait for connecting asynchronously to servers. pub mod future { - use REMOTE; + use future::REMOTE; use futures::{self, Async, Future}; use protocol::Proto; use serde::{Deserialize, Serialize}; diff --git a/src/lib.rs b/src/lib.rs index f8d7626..40eb941 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -86,8 +86,6 @@ pub extern crate tokio_proto; #[doc(hidden)] pub extern crate tokio_service; -pub use client::{sync, future}; - #[doc(hidden)] pub use client::Client; #[doc(hidden)] @@ -115,11 +113,21 @@ mod protocol; /// Provides a few different error types. mod errors; -use tokio_core::reactor::Remote; - -lazy_static! { - /// The `Remote` for the default reactor core. - pub static ref REMOTE: Remote = { - util::spawn_core() - }; +/// Utility specific to synchronous implementation. +pub mod sync { + pub use client::sync::*; +} + +/// Utility specific to futures implementation. +pub mod future { + pub use client::future::*; + use tokio_core::reactor::Remote; + use util; + + lazy_static! { + /// The `Remote` for the default reactor core. + pub static ref REMOTE: Remote = { + util::spawn_core() + }; + } } diff --git a/src/macros.rs b/src/macros.rs index c252587..eabef32 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -396,7 +396,7 @@ macro_rules! service { fn listen(self, addr: ::std::net::SocketAddr) -> $crate::ListenFuture { let (tx, rx) = $crate::futures::oneshot(); - $crate::REMOTE.spawn(move |handle| + $crate::future::REMOTE.spawn(move |handle| Ok(tx.complete(Self::listen_with(self, addr, handle.clone())))); @@ -542,7 +542,7 @@ macro_rules! service { { let addr = $crate::util::FirstSocketAddr::try_first_socket_addr(&addr)?; let (tx, rx) = $crate::futures::oneshot(); - $crate::REMOTE.spawn(move |handle| Ok(tx.complete(Self::listen_with(self, addr, handle.clone())))); + $crate::future::REMOTE.spawn(move |handle| Ok(tx.complete(Self::listen_with(self, addr, handle.clone())))); $crate::futures::Future::wait($crate::ListenFuture::from_oneshot(rx)) } diff --git a/src/server.rs b/src/server.rs index 5c8c96b..9537813 100644 --- a/src/server.rs +++ b/src/server.rs @@ -3,9 +3,10 @@ // Licensed under the MIT License, . // This file may not be copied, modified, or distributed except according to those terms. -use {REMOTE, net2}; +use net2; use bincode::serde::DeserializeError; use errors::WireError; +use future::REMOTE; use protocol::Proto; use futures::{self, Async, Future, Stream}; use serde::{Deserialize, Serialize};