mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-25 00:00:18 +02:00
Fixup Result-returning encode method
This commit is contained in:
+2
-2
@@ -242,7 +242,7 @@ pub trait Codec {
|
||||
/// This method will encode `msg` into the byte buffer provided by `buf`.
|
||||
/// The `buf` provided is an internal buffer of the `Framed` instance and
|
||||
/// will be written out when possible.
|
||||
fn encode(&mut self, msg: Self::Out) -> Result<Vec<u8>, io::Error>;
|
||||
fn encode(&mut self, msg: Self::Out, buf: &mut Vec<u8>) -> io::Result<()>;
|
||||
}
|
||||
|
||||
/// A unified `Stream` and `Sink` interface to an underlying `Io` object, using
|
||||
@@ -319,7 +319,7 @@ impl<T: Io, C: Codec> Sink for Framed<T, C> {
|
||||
}
|
||||
}
|
||||
|
||||
self.wr = self.codec.encode(item).unwrap();
|
||||
try!(self.codec.encode(item, &mut self.wr));
|
||||
Ok(AsyncSink::Ready)
|
||||
}
|
||||
|
||||
|
||||
@@ -28,8 +28,9 @@ impl Codec for LineCodec {
|
||||
Ok(buf.drain_to(amt))
|
||||
}
|
||||
|
||||
fn encode(&mut self, item: EasyBuf, into: &mut Vec<u8>) {
|
||||
fn encode(&mut self, item: EasyBuf, into: &mut Vec<u8>) -> io::Result<()> {
|
||||
into.extend_from_slice(item.as_slice());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user