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 {