From e4ef0881e6cd6c377ef4352d92f3abca908f013d Mon Sep 17 00:00:00 2001 From: Tim Kuehn Date: Wed, 11 Jan 2017 14:23:52 -0800 Subject: [PATCH] Update Cargo.toml to use crates.io releases of tokio deps. --- Cargo.toml | 14 ++++------- examples/concurrency.rs | 6 ++--- examples/pubsub.rs | 10 ++++---- examples/readme_errors.rs | 2 +- examples/readme_expanded.rs | 6 ++--- examples/readme_futures.rs | 4 ++-- examples/readme_sync.rs | 4 ++-- examples/server_calling_server.rs | 4 ++-- examples/throughput.rs | 2 +- examples/two_clients.rs | 8 +++---- src/client.rs | 2 +- src/lib.rs | 4 ++-- src/macros.rs | 40 +++++++++++++++---------------- src/protocol.rs | 2 -- 14 files changed, 51 insertions(+), 57 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e4eacae..f56e5ac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,8 +13,8 @@ description = "An RPC framework for Rust with a focus on ease of use." [dependencies] bincode = "0.6" byteorder = "0.5" -bytes = { git = "https://github.com/carllerche/bytes" } -futures = { git = "https://github.com/alexcrichton/futures-rs" } +bytes = "0.3" +futures = "0.1" lazy_static = "0.2" log = "0.3" scoped-pool = "1.0" @@ -22,15 +22,11 @@ serde = "0.8" serde_derive = "0.8" tarpc-plugins = { path = "src/plugins" } take = "0.1" -tokio-service = { git = "https://github.com/tokio-rs/tokio-service" } -tokio-proto = { git = "https://github.com/tokio-rs/tokio-proto" } -tokio-core = { git = "https://github.com/tokio-rs/tokio-core" } +tokio-service = "0.1" +tokio-proto = "0.1" +tokio-core = "0.1" net2 = "0.2" -[replace] -"tokio-core:0.1.3" = { git = "https://github.com/tokio-rs/tokio-core" } -"futures:0.1.7" = { git = "https://github.com/alexcrichton/futures-rs" } - [dev-dependencies] chrono = "0.2" env_logger = "0.3" diff --git a/examples/concurrency.rs b/examples/concurrency.rs index 621146b..5c6ddf9 100644 --- a/examples/concurrency.rs +++ b/examples/concurrency.rs @@ -50,7 +50,7 @@ impl Server { impl FutureService for Server { type ReadFut = CpuFuture, Never>; - fn read(&mut self, size: u32) -> Self::ReadFut { + fn read(&self, size: u32) -> Self::ReadFut { let request_number = self.request_count.fetch_add(1, Ordering::SeqCst); debug!("Server received read({}) no. {}", size, request_number); self.pool @@ -88,13 +88,13 @@ struct Stats { max: Option, } -fn run_once(mut clients: Vec, concurrency: u32) -> impl Future + 'static { +fn run_once(clients: Vec, concurrency: u32) -> impl Future + 'static { let start = Instant::now(); let num_clients = clients.len(); futures::stream::futures_unordered((0..concurrency as usize) .map(|iteration| (iteration + 1, iteration % num_clients)) .map(|(iteration, client_idx)| { - let mut client = &mut clients[client_idx]; + let client = &clients[client_idx]; let start = Instant::now(); debug!("Client {} reading (iteration {})...", client_idx, iteration); client.read(CHUNK_SIZE) diff --git a/examples/pubsub.rs b/examples/pubsub.rs index 3e770e6..26fea69 100644 --- a/examples/pubsub.rs +++ b/examples/pubsub.rs @@ -49,7 +49,7 @@ struct Subscriber { impl subscriber::FutureService for Subscriber { type ReceiveFut = futures::Finished<(), Never>; - fn receive(&mut self, message: String) -> Self::ReceiveFut { + fn receive(&self, message: String) -> Self::ReceiveFut { println!("{} received message: {}", self.id, message); futures::finished(()) } @@ -80,7 +80,7 @@ impl Publisher { impl publisher::FutureService for Publisher { type BroadcastFut = BoxFuture<(), Never>; - fn broadcast(&mut self, message: String) -> Self::BroadcastFut { + fn broadcast(&self, message: String) -> Self::BroadcastFut { futures::collect(self.clients .lock() .unwrap() @@ -94,7 +94,7 @@ impl publisher::FutureService for Publisher { type SubscribeFut = BoxFuture<(), Message>; - fn subscribe(&mut self, id: u32, address: SocketAddr) -> Self::SubscribeFut { + fn subscribe(&self, id: u32, address: SocketAddr) -> Self::SubscribeFut { let clients = self.clients.clone(); subscriber::FutureClient::connect(&address) .map(move |subscriber| { @@ -108,7 +108,7 @@ impl publisher::FutureService for Publisher { type UnsubscribeFut = BoxFuture<(), Never>; - fn unsubscribe(&mut self, id: u32) -> Self::UnsubscribeFut { + fn unsubscribe(&self, id: u32) -> Self::UnsubscribeFut { println!("Unsubscribing {}", id); self.clients.lock().unwrap().remove(&id).unwrap(); futures::finished(()).boxed() @@ -122,7 +122,7 @@ fn main() { .wait() .unwrap(); - let mut publisher_client = publisher::SyncClient::connect(publisher_addr).unwrap(); + let publisher_client = publisher::SyncClient::connect(publisher_addr).unwrap(); let subscriber1 = Subscriber::new(0); publisher_client.subscribe(0, subscriber1).unwrap(); diff --git a/examples/readme_errors.rs b/examples/readme_errors.rs index b8f27ea..37ef07b 100644 --- a/examples/readme_errors.rs +++ b/examples/readme_errors.rs @@ -39,7 +39,7 @@ impl Error for NoNameGiven { struct HelloServer; impl SyncService for HelloServer { - fn hello(&mut self, name: String) -> Result { + fn hello(&self, name: String) -> Result { if name == "" { Err(NoNameGiven) } else { diff --git a/examples/readme_expanded.rs b/examples/readme_expanded.rs index 246fae1..e6fd975 100644 --- a/examples/readme_expanded.rs +++ b/examples/readme_expanded.rs @@ -46,7 +46,7 @@ impl Service for HelloServer { type Error = io::Error; type Future = Box, Error = io::Error>>; - fn call(&mut self, request: Self::Request) -> Self::Future { + fn call(&self, request: Self::Request) -> Self::Future { Ok(Ok(format!("Hello, {}!", request.unwrap()))).into_future().boxed() } } @@ -60,7 +60,7 @@ impl FutureClient { tarpc::Client::connect_remotely(addr, &tarpc::future::REMOTE).map(FutureClient) } - pub fn hello(&mut self, name: String) + pub fn hello(&self, name: String) -> impl Future> + 'static { self.0.call(name).then(|msg| msg.unwrap()) @@ -73,7 +73,7 @@ fn main() { let addr = HelloServer::listen("localhost:10000".first_socket_addr()).wait().unwrap(); let f = FutureClient::connect(&addr) .map_err(tarpc::Error::from) - .and_then(|mut client| { + .and_then(|client| { let resp1 = client.hello("Mom".to_string()); info!("Sent first request."); diff --git a/examples/readme_futures.rs b/examples/readme_futures.rs index 90022a6..0afda18 100644 --- a/examples/readme_futures.rs +++ b/examples/readme_futures.rs @@ -26,7 +26,7 @@ struct HelloServer; impl FutureService for HelloServer { type HelloFut = futures::Finished; - fn hello(&mut self, name: String) -> Self::HelloFut { + fn hello(&self, name: String) -> Self::HelloFut { futures::finished(format!("Hello, {}!", name)) } } @@ -38,7 +38,7 @@ fn main() { core.run( FutureClient::connect(&addr) .map_err(tarpc::Error::from) - .and_then(|mut client| client.hello("Mom".to_string())) + .and_then(|client| client.hello("Mom".to_string())) .map(|resp| println!("{}", resp)) ).unwrap(); } diff --git a/examples/readme_sync.rs b/examples/readme_sync.rs index ecfbcdc..9e26cb5 100644 --- a/examples/readme_sync.rs +++ b/examples/readme_sync.rs @@ -22,7 +22,7 @@ service! { struct HelloServer; impl SyncService for HelloServer { - fn hello(&mut self, name: String) -> Result { + fn hello(&self, name: String) -> Result { Ok(format!("Hello, {}!", name)) } } @@ -30,6 +30,6 @@ impl SyncService for HelloServer { fn main() { let addr = "localhost:10000"; HelloServer.listen(addr).unwrap(); - let mut client = SyncClient::connect(addr).unwrap(); + let client = SyncClient::connect(addr).unwrap(); println!("{}", client.hello("Mom".to_string()).unwrap()); } diff --git a/examples/server_calling_server.rs b/examples/server_calling_server.rs index efebdf1..8f01d62 100644 --- a/examples/server_calling_server.rs +++ b/examples/server_calling_server.rs @@ -41,7 +41,7 @@ struct AddServer; impl AddFutureService for AddServer { type AddFut = futures::Finished; - fn add(&mut self, x: i32, y: i32) -> Self::AddFut { + fn add(&self, x: i32, y: i32) -> Self::AddFut { futures::finished(x + y) } } @@ -62,7 +62,7 @@ impl DoubleServer { impl DoubleFutureService for DoubleServer { type DoubleFut = BoxFuture; - fn double(&mut self, x: i32) -> Self::DoubleFut { + fn double(&self, x: i32) -> Self::DoubleFut { self.client .lock() .unwrap() diff --git a/examples/throughput.rs b/examples/throughput.rs index cf77e17..ad63fc6 100644 --- a/examples/throughput.rs +++ b/examples/throughput.rs @@ -44,7 +44,7 @@ struct Server; impl FutureService for Server { type ReadFut = futures::Finished>, Never>; - fn read(&mut self) -> Self::ReadFut { + fn read(&self) -> Self::ReadFut { futures::finished(BUF.clone()) } } diff --git a/examples/two_clients.rs b/examples/two_clients.rs index 7f82fa3..c8a06b1 100644 --- a/examples/two_clients.rs +++ b/examples/two_clients.rs @@ -31,7 +31,7 @@ struct Bar; impl bar::FutureService for Bar { type BarFut = futures::Finished; - fn bar(&mut self, i: i32) -> Self::BarFut { + fn bar(&self, i: i32) -> Self::BarFut { futures::finished(i) } } @@ -47,7 +47,7 @@ struct Baz; impl baz::FutureService for Baz { type BazFut = futures::Finished; - fn baz(&mut self, s: String) -> Self::BazFut { + fn baz(&self, s: String) -> Self::BazFut { futures::finished(format!("Hello, {}!", s)) } } @@ -61,8 +61,8 @@ fn main() { let bar_addr = Bar.listen("localhost:0".first_socket_addr()).wait().unwrap(); let baz_addr = Baz.listen("localhost:0".first_socket_addr()).wait().unwrap(); - let mut bar_client = bar::SyncClient::connect(&bar_addr).unwrap(); - let mut baz_client = baz::SyncClient::connect(&baz_addr).unwrap(); + let bar_client = bar::SyncClient::connect(&bar_addr).unwrap(); + let baz_client = baz::SyncClient::connect(&baz_addr).unwrap(); info!("Result: {:?}", bar_client.bar(17)); diff --git a/src/client.rs b/src/client.rs index 391e69c..7afdee7 100644 --- a/src/client.rs +++ b/src/client.rs @@ -55,7 +55,7 @@ impl Service for Client type Error = io::Error; type Future = ResponseFuture; - fn call(&mut self, request: Self::Request) -> Self::Future { + fn call(&self, request: Self::Request) -> Self::Future { self.inner.call(request).map(Self::map_err) } } diff --git a/src/lib.rs b/src/lib.rs index 2545776..f966480 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -45,7 +45,7 @@ //! struct HelloServer; //! //! impl SyncService for HelloServer { -//! fn hello(&mut self, name: String) -> Result { +//! fn hello(&self, name: String) -> Result { //! Ok(format!("Hello, {}!", name)) //! } //! } @@ -53,7 +53,7 @@ //! fn main() { //! let addr = "localhost:10000"; //! let _server = HelloServer.listen(addr); -//! let mut client = SyncClient::connect(addr).unwrap(); +//! let client = SyncClient::connect(addr).unwrap(); //! println!("{}", client.hello("Mom".to_string()).unwrap()); //! } //! ``` diff --git a/src/macros.rs b/src/macros.rs index 97fa505..0238404 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -386,7 +386,7 @@ macro_rules! service { } $(#[$attr])* - fn $fn_name(&mut self, $($arg:$in_),*) -> ty_snake_to_camel!(Self::$fn_name); + fn $fn_name(&self, $($arg:$in_),*) -> ty_snake_to_camel!(Self::$fn_name); )* } @@ -476,7 +476,7 @@ macro_rules! service { type Error = ::std::io::Error; type Future = __tarpc_service_FutureReply<__tarpc_service_S>; - fn call(&mut self, __tarpc_service_request: Self::Request) -> Self::Future { + fn call(&self, __tarpc_service_request: Self::Request) -> Self::Future { let __tarpc_service_request = match __tarpc_service_request { Ok(__tarpc_service_request) => __tarpc_service_request, Err(__tarpc_service_deserialize_err) => { @@ -509,7 +509,7 @@ macro_rules! service { } return __tarpc_service_FutureReply::$fn_name( $crate::futures::Future::then( - FutureService::$fn_name(&mut self.0, $($arg),*), + FutureService::$fn_name(&self.0, $($arg),*), __tarpc_service_wrap)); } )* @@ -529,7 +529,7 @@ macro_rules! service { { $( $(#[$attr])* - fn $fn_name(&mut self, $($arg:$in_),*) -> ::std::result::Result<$out, $error>; + fn $fn_name(&self, $($arg:$in_),*) -> ::std::result::Result<$out, $error>; )* } @@ -578,7 +578,7 @@ macro_rules! service { $crate::futures::Done<$out, $error>>, fn($crate::futures::Canceled) -> $error>>; } - fn $fn_name(&mut self, $($arg:$in_),*) -> ty_snake_to_camel!(Self::$fn_name) { + fn $fn_name(&self, $($arg:$in_),*) -> ty_snake_to_camel!(Self::$fn_name) { fn unimplemented(_: $crate::futures::Canceled) -> $error { // TODO(tikue): what do do if SyncService panics? unimplemented!() @@ -611,7 +611,7 @@ macro_rules! service { #[allow(unused)] #[derive(Clone, Debug)] /// The client stub that makes RPC calls to the server. Exposes a blocking interface. - pub struct SyncClient(::std::sync::Arc<::std::sync::Mutex>); + pub struct SyncClient(FutureClient); impl $crate::sync::Connect for SyncClient { fn connect(addr: A) -> ::std::result::Result @@ -620,7 +620,7 @@ macro_rules! service { let addr = $crate::util::FirstSocketAddr::try_first_socket_addr(&addr)?; let client = ::connect(&addr); let client = $crate::futures::Future::wait(client)?; - let client = SyncClient(::std::sync::Arc::new(::std::sync::Mutex::new(client))); + let client = SyncClient(client); ::std::result::Result::Ok(client) } } @@ -632,7 +632,7 @@ macro_rules! service { pub fn $fn_name(&self, $($arg: $in_),*) -> ::std::result::Result<$out, $crate::Error<$error>> { - let rpc = self.0.lock().unwrap().$fn_name($($arg),*); + let rpc = (self.0).$fn_name($($arg),*); $crate::futures::Future::wait(rpc) } )* @@ -719,13 +719,13 @@ macro_rules! service { $( #[allow(unused)] $(#[$attr])* - pub fn $fn_name(&mut self, $($arg: $in_),*) + pub fn $fn_name(&self, $($arg: $in_),*) -> impl $crate::futures::Future> + 'static { let __tarpc_service_req = __tarpc_service_Request::$fn_name(($($arg,)*)); let __tarpc_service_fut = - $crate::tokio_service::Service::call(&mut self.0, __tarpc_service_req); + $crate::tokio_service::Service::call(&self.0, __tarpc_service_req); $crate::futures::Future::then(__tarpc_service_fut, move |__tarpc_service_msg| { match __tarpc_service_msg? { @@ -822,10 +822,10 @@ mod functional_test { struct Server; impl SyncService for Server { - fn add(&mut self, x: i32, y: i32) -> Result { + fn add(&self, x: i32, y: i32) -> Result { Ok(x + y) } - fn hey(&mut self, name: String) -> Result { + fn hey(&self, name: String) -> Result { Ok(format!("Hey, {}.", name)) } } @@ -865,13 +865,13 @@ mod functional_test { impl FutureService for Server { type AddFut = Finished; - fn add(&mut self, x: i32, y: i32) -> Self::AddFut { + fn add(&self, x: i32, y: i32) -> Self::AddFut { finished(x + y) } type HeyFut = Finished; - fn hey(&mut self, name: String) -> Self::HeyFut { + fn hey(&self, name: String) -> Self::HeyFut { finished(format!("Hey, {}.", name)) } } @@ -880,7 +880,7 @@ mod functional_test { fn simple() { let _ = env_logger::init(); let addr = Server.listen("localhost:0".first_socket_addr()).wait().unwrap(); - let mut client = FutureClient::connect(&addr).wait().unwrap(); + let client = FutureClient::connect(&addr).wait().unwrap(); assert_eq!(3, client.add(1, 2).wait().unwrap()); assert_eq!("Hey, Tim.", client.hey("Tim".to_string()).wait().unwrap()); } @@ -889,7 +889,7 @@ mod functional_test { fn concurrent() { let _ = env_logger::init(); let addr = Server.listen("localhost:0".first_socket_addr()).wait().unwrap(); - let mut client = FutureClient::connect(&addr).wait().unwrap(); + let client = FutureClient::connect(&addr).wait().unwrap(); let req1 = client.add(1, 2); let req2 = client.add(3, 4); let req3 = client.hey("Tim".to_string()); @@ -902,7 +902,7 @@ mod functional_test { fn other_service() { let _ = env_logger::init(); let addr = Server.listen("localhost:0".first_socket_addr()).wait().unwrap(); - let mut client = + let client = super::other_service::FutureClient::connect(&addr).wait().unwrap(); match client.foo().wait().err().unwrap() { ::Error::ServerDeserialize(_) => {} // good @@ -923,7 +923,7 @@ mod functional_test { impl error_service::FutureService for ErrorServer { type BarFut = ::futures::Failed; - fn bar(&mut self) -> Self::BarFut { + fn bar(&self) -> Self::BarFut { info!("Called bar"); failed("lol jk".into()) } @@ -938,7 +938,7 @@ mod functional_test { let _ = env_logger::init(); let addr = ErrorServer.listen("localhost:0".first_socket_addr()).wait().unwrap(); - let mut client = FutureClient::connect(&addr).wait().unwrap(); + let client = FutureClient::connect(&addr).wait().unwrap(); client.bar() .then(move |result| { match result.err().unwrap() { @@ -952,7 +952,7 @@ mod functional_test { .wait() .unwrap(); - let mut client = SyncClient::connect(&addr).unwrap(); + let client = SyncClient::connect(&addr).unwrap(); match client.bar().err().unwrap() { ::Error::App(e) => { assert_eq!(e.description(), "lol jk"); diff --git a/src/protocol.rs b/src/protocol.rs index 86fd343..e3fc61e 100644 --- a/src/protocol.rs +++ b/src/protocol.rs @@ -121,7 +121,6 @@ impl ServerProto for Proto { type Response = Encode; type Request = Result; - type Error = io::Error; type Transport = Framed>; type BindTransport = Result; @@ -137,7 +136,6 @@ impl ClientProto for Proto { type Response = Result; type Request = Encode; - type Error = io::Error; type Transport = Framed>; type BindTransport = Result;