mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-02 00:00:11 +02:00
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:
+3
-3
@@ -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(()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user