mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-07 00:00:09 +02:00
codec: add {FramedRead,FramedWrite}::into_parts() (#7566)
This commit is contained in:
@@ -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> {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user