From 1bc50825f3901daff595b2c45ff04c48f0267198 Mon Sep 17 00:00:00 2001 From: Lucas Black Date: Fri, 1 Aug 2025 02:23:22 -0700 Subject: [PATCH] codec: add `FramedWrite::with_capacity` (#7493) --- tokio-util/src/codec/framed_write.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tokio-util/src/codec/framed_write.rs b/tokio-util/src/codec/framed_write.rs index b2cab069c..541aae9bf 100644 --- a/tokio-util/src/codec/framed_write.rs +++ b/tokio-util/src/codec/framed_write.rs @@ -47,6 +47,21 @@ where }, } } + + /// Creates a new `FramedWrite` with the given `encoder` and a buffer of `capacity` + /// initial size. + pub fn with_capacity(inner: T, encoder: E, capacity: usize) -> FramedWrite { + FramedWrite { + inner: FramedImpl { + inner, + codec: encoder, + state: WriteFrame { + buffer: BytesMut::with_capacity(capacity), + backpressure_boundary: capacity, + }, + }, + } + } } impl FramedWrite {