Merge pull request #827 from hyperium/enc-dec-get-ref
add get_ref methods to Encoder and Decoder
This commit is contained in:
@@ -94,6 +94,12 @@ pub struct BufReader<'a, R: io::Read + 'a> {
|
||||
reader: &'a mut R
|
||||
}
|
||||
|
||||
impl<'a, R: io::Read + 'a> BufReader<'a, R> {
|
||||
pub fn get_ref(&self) -> &R {
|
||||
self.reader
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, R: io::Read> Read for BufReader<'a, R> {
|
||||
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
||||
trace!("BufReader.read self={}, buf={}", self.buf.len(), buf.len());
|
||||
|
||||
@@ -44,6 +44,15 @@ enum Trans<'a, T: Read + 'a> {
|
||||
Buf(self::buffer::BufReader<'a, T>)
|
||||
}
|
||||
|
||||
impl<'a, T: Read + 'a> Trans<'a, T> {
|
||||
fn get_ref(&self) -> &T {
|
||||
match *self {
|
||||
Trans::Port(ref t) => &*t,
|
||||
Trans::Buf(ref buf) => buf.get_ref()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: Read + 'a> Read for Trans<'a, T> {
|
||||
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
||||
match *self {
|
||||
@@ -62,12 +71,27 @@ impl<'a, T: Read> Decoder<'a, T> {
|
||||
fn h1(decoder: &'a mut h1::Decoder, transport: Trans<'a, T>) -> Decoder<'a, T> {
|
||||
Decoder(DecoderImpl::H1(decoder, transport))
|
||||
}
|
||||
|
||||
/// Get a reference to the transport.
|
||||
pub fn get_ref(&self) -> &T {
|
||||
match self.0 {
|
||||
DecoderImpl::H1(_, ref transport) => transport.get_ref()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: Transport> Encoder<'a, T> {
|
||||
fn h1(encoder: &'a mut h1::Encoder, transport: &'a mut T) -> Encoder<'a, T> {
|
||||
Encoder(EncoderImpl::H1(encoder, transport))
|
||||
}
|
||||
|
||||
|
||||
/// Get a reference to the transport.
|
||||
pub fn get_ref(&self) -> &T {
|
||||
match self.0 {
|
||||
EncoderImpl::H1(_, ref transport) => &*transport
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: Read> Read for Decoder<'a, T> {
|
||||
|
||||
Reference in New Issue
Block a user