Change FutureService's associated types to be bounded by IntoFuture rather than Future.

It's strictly more flexible, because everything that impls Future impls IntoFuture, and it
additionally allows returning types like Result. Which is nice.
This commit is contained in:
Tim Kuehn
2017-02-07 19:58:11 -08:00
parent a1072c8c06
commit fe4eab38f1
7 changed files with 35 additions and 33 deletions

View File

@@ -12,6 +12,7 @@ extern crate lazy_static;
extern crate tarpc;
extern crate env_logger;
extern crate futures;
extern crate serde;
use futures::Future;
use std::io::{Read, Write, stdout};
@@ -24,7 +25,7 @@ use tarpc::client::sync::Connect;
use tarpc::util::{FirstSocketAddr, Never};
lazy_static! {
static ref BUF: Arc<Vec<u8>> = Arc::new(gen_vec(CHUNK_SIZE as usize));
static ref BUF: Arc<serde::bytes::ByteBuf> = Arc::new(gen_vec(CHUNK_SIZE as usize).into());
}
fn gen_vec(size: usize) -> Vec<u8> {
@@ -36,17 +37,17 @@ fn gen_vec(size: usize) -> Vec<u8> {
}
service! {
rpc read() -> Arc<Vec<u8>>;
rpc read() -> Arc<serde::bytes::ByteBuf>;
}
#[derive(Clone)]
struct Server;
impl FutureService for Server {
type ReadFut = futures::Finished<Arc<Vec<u8>>, Never>;
type ReadFut = Result<Arc<serde::bytes::ByteBuf>, Never>;
fn read(&self) -> Self::ReadFut {
futures::finished(BUF.clone())
Ok(BUF.clone())
}
}