diff --git a/src/bin/syndicate-server.rs b/src/bin/syndicate-server.rs index f44441a..82cafeb 100644 --- a/src/bin/syndicate-server.rs +++ b/src/bin/syndicate-server.rs @@ -22,24 +22,20 @@ fn other_eio(e: E) -> std::io::Error { std::io::Error::new(std::io::ErrorKind::Other, e.to_string()) } -fn translate_sink_err(e: tungstenite::Error) -> packets::EncodeError { - packets::EncodeError::Write(other_eio(e)) -} - fn encode_message(codec: &value::Codec, p: packets::S2C) -> - Result + Result { use serde::ser::Serialize; use preserves::ser::Serializer; let mut bs = Vec::with_capacity(128); let mut ser: Serializer<_, V, Syndicate> = Serializer::new(&mut bs, codec.encode_placeholders.as_ref()); - p.serialize(&mut ser).map_err(|e| std::io::Error::from(e))?; + p.serialize(&mut ser)?; Ok(Message::Binary(bs)) } fn message_encoder(codec: &value::Codec) - -> impl Fn(packets::S2C) -> futures::future::Ready> + '_ + -> impl Fn(packets::S2C) -> futures::future::Ready> + '_ { return move |p| futures::future::ready(encode_message(codec, p)); } @@ -97,7 +93,7 @@ async fn run_connection(connid: ConnId, let (o, i) = s.split(); let codec = packets::standard_preserves_codec(); let i = i.map(message_decoder(&codec)); - let o = o.sink_map_err(translate_sink_err).with(message_encoder(&codec)); + let o = o.sink_map_err(other_eio).with(message_encoder(&codec)); let mut p = Peer::new(connid, i, o); p.run(spaces, &config).await? }, diff --git a/src/dataspace.rs b/src/dataspace.rs index fb59dc1..4dd1cba 100644 --- a/src/dataspace.rs +++ b/src/dataspace.rs @@ -138,8 +138,7 @@ impl Dataspace { packets::Action::Assert(ref epname, ref assertion) => { let ac = self.peers.get_mut(&id).unwrap(); if ac.endpoints.contains_key(&epname) { - return Err(("Duplicate endpoint name".to_string(), - value::to_value(a).unwrap())); + return Err(("Duplicate endpoint name".to_string(), value::to_value(a))); } let ar = @@ -171,8 +170,7 @@ impl Dataspace { let ac = self.peers.get_mut(&id).unwrap(); match ac.endpoints.remove(epname) { None => { - return Err(("Nonexistent endpoint name".to_string(), - value::to_value(a).unwrap())); + return Err(("Nonexistent endpoint name".to_string(), value::to_value(a))); } Some(ep) => { self.remove_endpoint(&mut outbound_turns, id, epname, ep); diff --git a/src/packets.rs b/src/packets.rs index 292fe9e..daa7837 100644 --- a/src/packets.rs +++ b/src/packets.rs @@ -47,7 +47,7 @@ pub enum S2C { #[derive(Debug)] pub enum DecodeError { Read(io::Error), - Parse(value::error::Error, V), + Parse(value::de::error::Error, V), } impl From for DecodeError { @@ -67,45 +67,6 @@ impl std::error::Error for DecodeError { //--------------------------------------------------------------------------- -#[derive(Debug)] -pub enum EncodeError { - Write(io::Error), - Unparse(value::error::Error), -} - -impl From for EncodeError { - fn from(v: io::Error) -> Self { - EncodeError::Write(v) - } -} - -impl From> for EncodeError { - fn from(v: value::error::Error) -> Self { - EncodeError::Unparse(v) - } -} - -impl From for io::Error { - fn from(v: EncodeError) -> Self { - match v { - EncodeError::Write(e) => e, - EncodeError::Unparse(e) => - Self::new(io::ErrorKind::InvalidData, format!("{:?}", e)), - } - } -} - -impl std::fmt::Display for EncodeError { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(f, "{:?}", self) - } -} - -impl std::error::Error for EncodeError { -} - -//--------------------------------------------------------------------------- - pub struct Codec { codec: value::Codec, ph_in: PhantomData, @@ -161,7 +122,7 @@ impl tokio_util::codec::Decoder for Code impl tokio_util::codec::Encoder for Codec { - type Error = EncodeError; + type Error = io::Error; fn encode(&mut self, item: OutT, bs: &mut BytesMut) -> Result<(), Self::Error> { let mut w = bs.writer(); let mut ser: Serializer<_, V, Syndicate> = Serializer::new(&mut w, self.codec.encode_placeholders.as_ref()); diff --git a/src/peer.rs b/src/peer.rs index de1595a..797dd0a 100644 --- a/src/peer.rs +++ b/src/peer.rs @@ -20,7 +20,7 @@ pub type ResultC2S = Result; pub struct Peer where I: Stream + Send, - O: Sink, + O: Sink, { id: ConnId, tx: UnboundedSender, @@ -36,7 +36,7 @@ fn err(s: &str, ctx: V) -> packets::S2C { impl Peer where I: Stream + Send, - O: Sink, + O: Sink, { pub fn new(id: ConnId, i: I, o: O) -> Self { let (tx, rx) = unbounded_channel(); @@ -116,7 +116,7 @@ where I: Stream + Send, packets::C2S::Pong() => (), packets::C2S::Connect(_) => { - to_send.push(err("Unexpected Connect", value::to_value(p).unwrap())); + to_send.push(err("Unexpected Connect", value::to_value(p))); running = false; } } @@ -184,7 +184,7 @@ where I: Stream + Send, impl Drop for Peer where I: Stream + Send, - O: Sink, + O: Sink, { fn drop(&mut self) { if let Some(ref s) = self.space {