mirror of
https://github.com/OMGeeky/tarpc.git
synced 2026-01-20 02:05:58 +01:00
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:
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user