util: add mutable reference getters for codecs to pinned Framed (#4372)

This commit is contained in:
Tom Dohrmann
2022-01-03 22:21:43 +01:00
committed by GitHub
parent 12dd06336d
commit 4a12163d7c
3 changed files with 19 additions and 0 deletions
+9
View File
@@ -204,6 +204,15 @@ impl<T, U> Framed<T, U> {
&mut self.inner.codec
}
/// Returns a mutable reference to the underlying codec wrapped by
/// `Framed`.
///
/// Note that care should be taken to not tamper with the underlying codec
/// as it may corrupt the stream of frames otherwise being worked with.
pub fn codec_pin_mut(self: Pin<&mut Self>) -> &mut U {
self.project().inner.project().codec
}
/// Returns a reference to the read buffer.
pub fn read_buffer(&self) -> &BytesMut {
&self.inner.state.read.buffer
+5
View File
@@ -108,6 +108,11 @@ impl<T, D> FramedRead<T, D> {
&mut self.inner.codec
}
/// Returns a mutable reference to the underlying decoder.
pub fn decoder_pin_mut(self: Pin<&mut Self>) -> &mut D {
self.project().inner.project().codec
}
/// Returns a reference to the read buffer.
pub fn read_buffer(&self) -> &BytesMut {
&self.inner.state.buffer
+5
View File
@@ -88,6 +88,11 @@ impl<T, E> FramedWrite<T, E> {
&mut self.inner.codec
}
/// Returns a mutable reference to the underlying encoder.
pub fn encoder_pin_mut(self: Pin<&mut Self>) -> &mut E {
self.project().inner.project().codec
}
/// Returns a reference to the write buffer.
pub fn write_buffer(&self) -> &BytesMut {
&self.inner.state.buffer