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
This commit is contained in:
Roman
2018-01-16 08:49:59 -08:00
committed by Alex Crichton
parent dac13c1df4
commit 025f52aadc
6 changed files with 92 additions and 34 deletions
+3 -3
View File
@@ -197,6 +197,7 @@ struct Codec {
impl UdpCodec for Codec {
type In = ();
type Out = &'static [u8];
type Error = io::Error;
fn decode(&mut self, src: &SocketAddr, buf: &[u8]) -> io::Result<Self::In> {
assert_eq!(src, &self.from);
@@ -204,10 +205,10 @@ impl UdpCodec for Codec {
Ok(())
}
fn encode(&mut self, msg: Self::Out, buf: &mut Vec<u8>) -> SocketAddr {
fn encode(&mut self, msg: Self::Out, buf: &mut Vec<u8>) -> io::Result<SocketAddr> {
assert_eq!(msg, self.data);
buf.extend_from_slice(msg);
self.to
Ok(self.to)
}
}
@@ -241,4 +242,3 @@ fn send_framed() {
assert_eq!(received.0, Some(()));
}
}