Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update serde to 0.7 #30

Merged
merged 3 commits into from
Apr 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions tarpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ readme = "../README.md"
description = "An RPC framework for Rust with a focus on ease of use."

[dependencies]
bincode = "^0.4.0"
log = "^0.3.5"
scoped-pool = "^0.1.5"
serde = "^0.6.14"
bincode = "^0.5"
log = "^0.3"
scoped-pool = "^0.1"
serde = "^0.7"

[dev-dependencies]
env_logger = "^0.3.2"
lazy_static = "^0.1"
env_logger = "^0.3"
9 changes: 5 additions & 4 deletions tarpc/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ macro_rules! impl_serialize {
match *self {
$(
$impler::$name(ref field) =>
$crate::macros::serde::Serializer::visit_newtype_variant(
$crate::macros::serde::Serializer::serialize_newtype_variant(
serializer,
stringify!($impler),
$n,
Expand Down Expand Up @@ -165,11 +165,12 @@ macro_rules! impl_deserialize {
}
)*
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)
}
}

Expand Down Expand Up @@ -197,7 +198,7 @@ macro_rules! impl_deserialize {
stringify!($name)
),*
];
deserializer.visit_enum(stringify!($impler), VARIANTS, __Visitor)
deserializer.deserialize_enum(stringify!($impler), VARIANTS, __Visitor)
}
}
);
Expand Down
21 changes: 11 additions & 10 deletions tarpc/src/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use bincode::{self, SizeLimit};
use bincode::serde::{deserialize_from, serialize_into};
use serde;
use serde::de::value::Error::EndOfStream;
use std::io::{self, Read, Write};
use std::convert;
use std::sync::Arc;
Expand Down Expand Up @@ -40,10 +41,14 @@ impl convert::From<bincode::serde::SerializeError> for Error {
impl convert::From<bincode::serde::DeserializeError> for Error {
fn from(err: bincode::serde::DeserializeError) -> Error {
match err {
bincode::serde::DeserializeError::IoError(ref err)
if err.kind() == io::ErrorKind::ConnectionReset => Error::ConnectionBroken,
bincode::serde::DeserializeError::EndOfStreamError => Error::ConnectionBroken,
bincode::serde::DeserializeError::IoError(err) => Error::Io(Arc::new(err)),
bincode::serde::DeserializeError::Serde(EndOfStream) => Error::ConnectionBroken,
bincode::serde::DeserializeError::IoError(err) => {
match err.kind() {
io::ErrorKind::ConnectionReset |
io::ErrorKind::UnexpectedEof => Error::ConnectionBroken,
_ => Error::Io(Arc::new(err)),
}
}
err => panic!("Unexpected error during deserialization: {:?}", err),
}
}
Expand Down Expand Up @@ -180,9 +185,7 @@ mod test {
let _ = env_logger::init();
let server = Arc::new(Server::new());
let serve_handle = server.spawn_with_config("localhost:0",
Config {
timeout: Some(Duration::new(0, 10))
})
Config { timeout: Some(Duration::new(0, 10)) })
.unwrap();
let addr = serve_handle.local_addr().clone();
let client: Client<(), u64> = Client::new(addr).unwrap();
Expand All @@ -196,9 +199,7 @@ mod test {
let _ = env_logger::init();
let server = Arc::new(Server::new());
let serve_handle = server.spawn_with_config("localhost:0",
Config {
timeout: test_timeout(),
})
Config { timeout: test_timeout() })
.unwrap();
let addr = serve_handle.local_addr().clone();
let client: Arc<Client<(), u64>> = Arc::new(Client::new(addr).unwrap());
Expand Down
16 changes: 8 additions & 8 deletions tarpc/src/protocol/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ impl<T: Serialize> Serialize for Packet<T> {
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
where S: Serializer
{
serializer.visit_struct(PACKET,
MapVisitor {
value: self,
state: 0,
})
serializer.serialize_struct(PACKET,
MapVisitor {
value: self,
state: 0,
})
}
}

Expand All @@ -40,11 +40,11 @@ impl<'a, T: Serialize> ser::MapVisitor for MapVisitor<'a, T> {
match self.state {
0 => {
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 => {
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),
}
Expand All @@ -62,7 +62,7 @@ impl<T: Deserialize> Deserialize for Packet<T> {
where D: Deserializer
{
const FIELDS: &'static [&'static str] = &[RPC_ID, MESSAGE];
deserializer.visit_struct(PACKET, FIELDS, Visitor(PhantomData))
deserializer.deserialize_struct(PACKET, FIELDS, Visitor(PhantomData))
}
}

Expand Down
4 changes: 2 additions & 2 deletions tarpc/src/protocol/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,15 @@ pub trait Serve: Send + Sync + Sized {
/// spawn
fn spawn<A>(self, addr: A) -> io::Result<ServeHandle>
where A: ToSocketAddrs,
Self: 'static,
Self: 'static
{
self.spawn_with_config(addr, Config::default())
}

/// spawn
fn spawn_with_config<A>(self, addr: A, config: Config) -> io::Result<ServeHandle>
where A: ToSocketAddrs,
Self: 'static,
Self: 'static
{
let listener = try!(TcpListener::bind(&addr));
let addr = try!(listener.local_addr());
Expand Down