mirror of
https://github.com/OMGeeky/tarpc.git
synced 2026-02-23 15:49:54 +01:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
32e0b0d7f8 | ||
|
|
b87c52758e | ||
|
|
9235e12904 | ||
|
|
265fe56fa6 | ||
|
|
7b5b29a9c3 | ||
|
|
fe978f2c56 | ||
|
|
44f472c65c | ||
|
|
e8fcf0e4de | ||
|
|
2eb0b2cc83 | ||
|
|
a8766a9200 | ||
|
|
ef96c87226 | ||
|
|
3543b34f2b | ||
|
|
4c1d15f8ea | ||
|
|
ece1cc60b9 | ||
|
|
7d8a508379 |
@@ -68,7 +68,7 @@ items expanded by a `service!` invocation.
|
|||||||
|
|
||||||
## Additional Features
|
## Additional Features
|
||||||
- Concurrent requests from a single client.
|
- Concurrent requests from a single client.
|
||||||
- Any type that `impl`s `serde`'s Serialize` and `Deserialize` can be used in the rpc signatures.
|
- Any type that `impl`s `serde`'s `Serialize` and `Deserialize` can be used in the rpc signatures.
|
||||||
- Attributes can be specified on rpc methods. These will be included on both the `Service` trait
|
- Attributes can be specified on rpc methods. These will be included on both the `Service` trait
|
||||||
methods as well as on the `Client`'s stub methods.
|
methods as well as on the `Client`'s stub methods.
|
||||||
- Just like regular fns, the return type can be left off when it's `-> ()`.
|
- Just like regular fns, the return type can be left off when it's `-> ()`.
|
||||||
|
|||||||
@@ -92,9 +92,8 @@ FMTRESULT=0
|
|||||||
for file in $(git diff --name-only --cached);
|
for file in $(git diff --name-only --cached);
|
||||||
do
|
do
|
||||||
if [ ${file: -3} == ".rs" ]; then
|
if [ ${file: -3} == ".rs" ]; then
|
||||||
HASH=$(shasum $file)
|
diff=$(rustfmt --skip-children --write-mode=diff $file)
|
||||||
NEW_HASH=$(rustfmt --write-mode=display $file | shasum)
|
if grep --quiet "^Diff at line" <<< "$diff"; then
|
||||||
if [ "${HASH}" != "${NEW_HASH}" ]; then
|
|
||||||
FMTRESULT=1
|
FMTRESULT=1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -105,6 +104,7 @@ if [ "${TARPC_SKIP_RUSTFMT}" == 1 ]; then
|
|||||||
elif [ ${FMTRESULT} != 0 ]; then
|
elif [ ${FMTRESULT} != 0 ]; then
|
||||||
FAILED=1
|
FAILED=1
|
||||||
printf "${FAILURE}\n"
|
printf "${FAILURE}\n"
|
||||||
|
echo "$diff" | sed '/Using rustfmt.*$/d'
|
||||||
else
|
else
|
||||||
printf "${SUCCESS}\n"
|
printf "${SUCCESS}\n"
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "tarpc"
|
name = "tarpc"
|
||||||
version = "0.3.0"
|
version = "0.4.0"
|
||||||
authors = ["Adam Wright <adam.austin.wright@gmail.com>", "Tim Kuehn <timothy.j.kuehn@gmail.com>"]
|
authors = ["Adam Wright <adam.austin.wright@gmail.com>", "Tim Kuehn <timothy.j.kuehn@gmail.com>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
documentation = "https://google.github.io/tarpc"
|
documentation = "https://google.github.io/tarpc"
|
||||||
@@ -11,11 +11,11 @@ readme = "../README.md"
|
|||||||
description = "An RPC framework for Rust with a focus on ease of use."
|
description = "An RPC framework for Rust with a focus on ease of use."
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bincode = "^0.4.0"
|
bincode = "^0.5"
|
||||||
log = "^0.3.5"
|
log = "^0.3"
|
||||||
scoped-pool = "^0.1.5"
|
scoped-pool = "^0.1"
|
||||||
serde = "^0.6.14"
|
serde = "^0.7"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
lazy_static = "^0.1.15"
|
lazy_static = "^0.1"
|
||||||
env_logger = "^0.3.2"
|
env_logger = "^0.3"
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ macro_rules! impl_serialize {
|
|||||||
match *self {
|
match *self {
|
||||||
$(
|
$(
|
||||||
$impler::$name(ref field) =>
|
$impler::$name(ref field) =>
|
||||||
$crate::macros::serde::Serializer::visit_newtype_variant(
|
$crate::macros::serde::Serializer::serialize_newtype_variant(
|
||||||
serializer,
|
serializer,
|
||||||
stringify!($impler),
|
stringify!($impler),
|
||||||
$n,
|
$n,
|
||||||
@@ -165,11 +165,12 @@ macro_rules! impl_deserialize {
|
|||||||
}
|
}
|
||||||
)*
|
)*
|
||||||
return ::std::result::Result::Err(
|
return ::std::result::Result::Err(
|
||||||
$crate::macros::serde::de::Error::syntax("expected a field")
|
$crate::macros::serde::de::Error::custom(
|
||||||
|
format!("No variants have a value of {}!", value))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
deserializer.visit_struct_field(__FieldVisitor)
|
deserializer.deserialize_struct_field(__FieldVisitor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,7 +198,7 @@ macro_rules! impl_deserialize {
|
|||||||
stringify!($name)
|
stringify!($name)
|
||||||
),*
|
),*
|
||||||
];
|
];
|
||||||
deserializer.visit_enum(stringify!($impler), VARIANTS, __Visitor)
|
deserializer.deserialize_enum(stringify!($impler), VARIANTS, __Visitor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
use bincode::{self, SizeLimit};
|
use bincode::{self, SizeLimit};
|
||||||
use bincode::serde::{deserialize_from, serialize_into};
|
use bincode::serde::{deserialize_from, serialize_into};
|
||||||
use serde;
|
use serde;
|
||||||
|
use serde::de::value::Error::EndOfStream;
|
||||||
use std::io::{self, Read, Write};
|
use std::io::{self, Read, Write};
|
||||||
use std::convert;
|
use std::convert;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@@ -40,10 +41,14 @@ impl convert::From<bincode::serde::SerializeError> for Error {
|
|||||||
impl convert::From<bincode::serde::DeserializeError> for Error {
|
impl convert::From<bincode::serde::DeserializeError> for Error {
|
||||||
fn from(err: bincode::serde::DeserializeError) -> Error {
|
fn from(err: bincode::serde::DeserializeError) -> Error {
|
||||||
match err {
|
match err {
|
||||||
bincode::serde::DeserializeError::IoError(ref err)
|
bincode::serde::DeserializeError::Serde(EndOfStream) => Error::ConnectionBroken,
|
||||||
if err.kind() == io::ErrorKind::ConnectionReset => Error::ConnectionBroken,
|
bincode::serde::DeserializeError::IoError(err) => {
|
||||||
bincode::serde::DeserializeError::EndOfStreamError => Error::ConnectionBroken,
|
match err.kind() {
|
||||||
bincode::serde::DeserializeError::IoError(err) => Error::Io(Arc::new(err)),
|
io::ErrorKind::ConnectionReset |
|
||||||
|
io::ErrorKind::UnexpectedEof => Error::ConnectionBroken,
|
||||||
|
_ => Error::Io(Arc::new(err)),
|
||||||
|
}
|
||||||
|
}
|
||||||
err => panic!("Unexpected error during deserialization: {:?}", err),
|
err => panic!("Unexpected error during deserialization: {:?}", err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -180,9 +185,7 @@ mod test {
|
|||||||
let _ = env_logger::init();
|
let _ = env_logger::init();
|
||||||
let server = Arc::new(Server::new());
|
let server = Arc::new(Server::new());
|
||||||
let serve_handle = server.spawn_with_config("localhost:0",
|
let serve_handle = server.spawn_with_config("localhost:0",
|
||||||
Config {
|
Config { timeout: Some(Duration::new(0, 10)) })
|
||||||
timeout: Some(Duration::new(0, 10))
|
|
||||||
})
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let addr = serve_handle.local_addr().clone();
|
let addr = serve_handle.local_addr().clone();
|
||||||
let client: Client<(), u64> = Client::new(addr).unwrap();
|
let client: Client<(), u64> = Client::new(addr).unwrap();
|
||||||
@@ -196,9 +199,7 @@ mod test {
|
|||||||
let _ = env_logger::init();
|
let _ = env_logger::init();
|
||||||
let server = Arc::new(Server::new());
|
let server = Arc::new(Server::new());
|
||||||
let serve_handle = server.spawn_with_config("localhost:0",
|
let serve_handle = server.spawn_with_config("localhost:0",
|
||||||
Config {
|
Config { timeout: test_timeout() })
|
||||||
timeout: test_timeout(),
|
|
||||||
})
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let addr = serve_handle.local_addr().clone();
|
let addr = serve_handle.local_addr().clone();
|
||||||
let client: Arc<Client<(), u64>> = Arc::new(Client::new(addr).unwrap());
|
let client: Arc<Client<(), u64>> = Arc::new(Client::new(addr).unwrap());
|
||||||
|
|||||||
@@ -19,11 +19,11 @@ impl<T: Serialize> Serialize for Packet<T> {
|
|||||||
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
||||||
where S: Serializer
|
where S: Serializer
|
||||||
{
|
{
|
||||||
serializer.visit_struct(PACKET,
|
serializer.serialize_struct(PACKET,
|
||||||
MapVisitor {
|
MapVisitor {
|
||||||
value: self,
|
value: self,
|
||||||
state: 0,
|
state: 0,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,11 +40,11 @@ impl<'a, T: Serialize> ser::MapVisitor for MapVisitor<'a, T> {
|
|||||||
match self.state {
|
match self.state {
|
||||||
0 => {
|
0 => {
|
||||||
self.state += 1;
|
self.state += 1;
|
||||||
Ok(Some(try!(serializer.visit_struct_elt(RPC_ID, &self.value.rpc_id))))
|
Ok(Some(try!(serializer.serialize_struct_elt(RPC_ID, &self.value.rpc_id))))
|
||||||
}
|
}
|
||||||
1 => {
|
1 => {
|
||||||
self.state += 1;
|
self.state += 1;
|
||||||
Ok(Some(try!(serializer.visit_struct_elt(MESSAGE, &self.value.message))))
|
Ok(Some(try!(serializer.serialize_struct_elt(MESSAGE, &self.value.message))))
|
||||||
}
|
}
|
||||||
_ => Ok(None),
|
_ => Ok(None),
|
||||||
}
|
}
|
||||||
@@ -62,7 +62,7 @@ impl<T: Deserialize> Deserialize for Packet<T> {
|
|||||||
where D: Deserializer
|
where D: Deserializer
|
||||||
{
|
{
|
||||||
const FIELDS: &'static [&'static str] = &[RPC_ID, MESSAGE];
|
const FIELDS: &'static [&'static str] = &[RPC_ID, MESSAGE];
|
||||||
deserializer.visit_struct(PACKET, FIELDS, Visitor(PhantomData))
|
deserializer.deserialize_struct(PACKET, FIELDS, Visitor(PhantomData))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -214,7 +214,7 @@ pub trait Serve: Send + Sync + Sized {
|
|||||||
/// spawn
|
/// spawn
|
||||||
fn spawn<A>(self, addr: A) -> io::Result<ServeHandle>
|
fn spawn<A>(self, addr: A) -> io::Result<ServeHandle>
|
||||||
where A: ToSocketAddrs,
|
where A: ToSocketAddrs,
|
||||||
Self: 'static,
|
Self: 'static
|
||||||
{
|
{
|
||||||
self.spawn_with_config(addr, Config::default())
|
self.spawn_with_config(addr, Config::default())
|
||||||
}
|
}
|
||||||
@@ -222,7 +222,7 @@ pub trait Serve: Send + Sync + Sized {
|
|||||||
/// spawn
|
/// spawn
|
||||||
fn spawn_with_config<A>(self, addr: A, config: Config) -> io::Result<ServeHandle>
|
fn spawn_with_config<A>(self, addr: A, config: Config) -> io::Result<ServeHandle>
|
||||||
where A: ToSocketAddrs,
|
where A: ToSocketAddrs,
|
||||||
Self: 'static,
|
Self: 'static
|
||||||
{
|
{
|
||||||
let listener = try!(TcpListener::bind(&addr));
|
let listener = try!(TcpListener::bind(&addr));
|
||||||
let addr = try!(listener.local_addr());
|
let addr = try!(listener.local_addr());
|
||||||
|
|||||||
Reference in New Issue
Block a user