From 025f52aadcc8b35d47701241f675623c7f1d42ff Mon Sep 17 00:00:00 2001 From: Roman Date: Tue, 16 Jan 2018 19:49:59 +0300 Subject: 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) -> Result; ``` Closes https://github.com/tokio-rs/tokio/issues/79 * Fix compilation error from `mio` crate --- examples/udp-codec.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'examples/udp-codec.rs') 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); type Out = (SocketAddr, Vec); + type Error = io::Error; fn decode(&mut self, addr: &SocketAddr, buf: &[u8]) -> io::Result { Ok((*addr, buf.to_vec())) } - fn encode(&mut self, (addr, buf): Self::Out, into: &mut Vec) -> SocketAddr { + fn encode(&mut self, (addr, buf): Self::Out, into: &mut Vec) -> io::Result { into.extend(buf); - addr + Ok(addr) } } -- cgit v1.2.3