summaryrefslogtreecommitdiffstats
path: root/examples/udp-codec.rs
diff options
context:
space:
mode:
authorRoman <humbug@deeptown.org>2018-01-16 19:49:59 +0300
committerAlex Crichton <alex@alexcrichton.com>2018-01-16 08:49:59 -0800
commit025f52aadcc8b35d47701241f675623c7f1d42ff (patch)
tree72136f3a355a2686b597c24661a68a751feb4d1a /examples/udp-codec.rs
parentdac13c1df4a5baa8e7e4c25749585c2d90278af0 (diff)
Fix UdpCodec::encode (#85)
* Refactor UDP SendDgram & RecvDgram Get rid of unnamed structs in the favor of private structs with named fields * Change the signature of UdpCodec::encode Now it is: ``` fn encode(&mut self, msg: Self::Out, buf: &mut Vec<u8>) -> Result<SocketAddr, Self::Error>; ``` Closes https://github.com/tokio-rs/tokio/issues/79 * Fix compilation error from `mio` crate
Diffstat (limited to 'examples/udp-codec.rs')
-rw-r--r--examples/udp-codec.rs5
1 files changed, 3 insertions, 2 deletions
diff --git a/examples/udp-codec.rs b/examples/udp-codec.rs
index ff9ae553..c874ebd7 100644
--- a/examples/udp-codec.rs
+++ b/examples/udp-codec.rs
@@ -24,14 +24,15 @@ pub struct LineCodec;
impl UdpCodec for LineCodec {
type In = (SocketAddr, Vec<u8>);
type Out = (SocketAddr, Vec<u8>);
+ type Error = io::Error;
fn decode(&mut self, addr: &SocketAddr, buf: &[u8]) -> io::Result<Self::In> {
Ok((*addr, buf.to_vec()))
}
- fn encode(&mut self, (addr, buf): Self::Out, into: &mut Vec<u8>) -> SocketAddr {
+ fn encode(&mut self, (addr, buf): Self::Out, into: &mut Vec<u8>) -> io::Result<SocketAddr> {
into.extend(buf);
- addr
+ Ok(addr)
}
}