Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tokio-util/src/codec/framed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
14 changes: 14 additions & 0 deletions tokio-util/src/codec/framed_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`].
///
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions tokio-util/src/codec/framed_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
///
Expand Down Expand Up @@ -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
Expand Down
Loading