Skip to content

Conversation

@conradludgate
Copy link
Contributor

Motivation

Minor ergonomics, mostly. To avoid Framed::from_parts(parts) which always reserves 8KiB in the read and write buffers I have been using

fn my_from_parts<T, U>(parts: FramedParts<T, U>) -> Framed<T, U> {
    let mut framed = Framed::with_capacity(parts.io, parts.codec, 0);
    *framed.read_buffer_mut() = parts.read_buf;
    *framed.write_buffer_mut() = parts.write_buf;
    framed
}

It's a minor annoyance that the above function actually needs a T: AsyncRead + AsyncWrite bounds, whereas Framed::from_parts(parts) doesn't.

Solution

Remove the bounds on all Framed constructors.

@ADD-SP ADD-SP added A-tokio-util Area: The tokio-util crate M-codec Module: tokio-util/codec labels Oct 29, 2025
@conradludgate conradludgate requested a review from ADD-SP October 29, 2025 11:38
Copy link
Member

@ADD-SP ADD-SP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ADD-SP ADD-SP changed the title remove unnecessary bounds on Framed constructors codec: remove unnecessary trait bounds on Framed Oct 29, 2025
@ADD-SP ADD-SP changed the title codec: remove unnecessary trait bounds on Framed codec: remove unnecessary trait bounds on Framed constructors Oct 29, 2025
@ADD-SP ADD-SP changed the title codec: remove unnecessary trait bounds on Framed constructors codec: remove unnecessary trait bounds on all Framed constructors Oct 29, 2025
@ADD-SP ADD-SP merged commit 4421022 into tokio-rs:master Oct 29, 2025
87 checks passed
benjaminran pushed a commit to benjaminran/tokio that referenced this pull request Nov 6, 2025
Daksh14 pushed a commit to Daksh14/tokio that referenced this pull request Nov 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-tokio-util Area: The tokio-util crate M-codec Module: tokio-util/codec

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants