codec: add {FramedRead,FramedWrite}::into_parts() (#7566)

This commit is contained in:
Varun Doshi
2025-09-03 13:38:51 +02:00
committed by GitHub
parent adc3e19ba7
commit c8371d45bc
3 changed files with 29 additions and 1 deletions
+1 -1
View File
@@ -377,7 +377,7 @@ pub struct FramedParts<T, U> {
/// This private field allows us to add additional fields in the future in a
/// backwards compatible way.
_priv: (),
pub(crate) _priv: (),
}
impl<T, U> FramedParts<T, U> {
+14
View File
@@ -11,6 +11,8 @@ use std::fmt;
use std::pin::Pin;
use std::task::{Context, Poll};
use super::FramedParts;
pin_project! {
/// A [`Stream`] of messages decoded from an [`AsyncRead`].
///
@@ -153,6 +155,18 @@ impl<T, D> FramedRead<T, D> {
pub fn read_buffer_mut(&mut self) -> &mut BytesMut {
&mut self.inner.state.buffer
}
/// Consumes the `FramedRead`, returning its underlying I/O stream, the buffer
/// with unprocessed data, and the codec.
pub fn into_parts(self) -> FramedParts<T, D> {
FramedParts {
io: self.inner.inner,
codec: self.inner.codec,
read_buf: self.inner.state.buffer,
write_buf: BytesMut::new(),
_priv: (),
}
}
}
// This impl just defers to the underlying FramedImpl
+14
View File
@@ -12,6 +12,8 @@ use std::io;
use std::pin::Pin;
use std::task::{Context, Poll};
use super::FramedParts;
pin_project! {
/// A [`Sink`] of frames encoded to an `AsyncWrite`.
///
@@ -159,6 +161,18 @@ impl<T, E> FramedWrite<T, E> {
pub fn set_backpressure_boundary(&mut self, boundary: usize) {
self.inner.state.backpressure_boundary = boundary;
}
/// Consumes the `FramedWrite`, returning its underlying I/O stream, the buffer
/// with unprocessed data, and the codec.
pub fn into_parts(self) -> FramedParts<T, E> {
FramedParts {
io: self.inner.inner,
codec: self.inner.codec,
read_buf: BytesMut::new(),
write_buf: self.inner.state.buffer,
_priv: (),
}
}
}
// This impl just defers to the underlying FramedImpl