@@ -7,7 +7,7 @@ use std::{
77 sync:: Arc ,
88} ;
99
10- use bytes:: { Bytes , BytesMut } ;
10+ use bytes:: { BufMut , Bytes , BytesMut } ;
1111use frame:: StreamMetaVec ;
1212use rand:: { Rng , SeedableRng , rngs:: StdRng } ;
1313use thiserror:: Error ;
@@ -757,7 +757,7 @@ impl Connection {
757757 self . receiving_ecn ,
758758 & mut SentFrames :: default ( ) ,
759759 & mut self . spaces [ space_id] ,
760- buf . buf ,
760+ & mut buf,
761761 & mut self . stats ,
762762 ) ;
763763 }
@@ -844,7 +844,7 @@ impl Connection {
844844 let sent = self . populate_packet (
845845 now,
846846 space_id,
847- buf . buf ,
847+ & mut buf,
848848 builder. max_size ,
849849 builder. exact_number ,
850850 ) ;
@@ -3022,7 +3022,7 @@ impl Connection {
30223022 & mut self ,
30233023 now : Instant ,
30243024 space_id : SpaceId ,
3025- buf : & mut Vec < u8 > ,
3025+ buf : & mut ( impl BufMut + BufLen ) ,
30263026 max_size : usize ,
30273027 pn : u64 ,
30283028 ) -> SentFrames {
@@ -3288,7 +3288,7 @@ impl Connection {
32883288 receiving_ecn : bool ,
32893289 sent : & mut SentFrames ,
32903290 space : & mut PacketSpace ,
3291- buf : & mut Vec < u8 > ,
3291+ buf : & mut impl BufMut ,
32923292 stats : & mut ConnectionStats ,
32933293 ) {
32943294 debug_assert ! ( !space. pending_acks. ranges( ) . is_empty( ) ) ;
@@ -3958,6 +3958,23 @@ fn negotiate_max_idle_timeout(x: Option<VarInt>, y: Option<VarInt>) -> Option<Du
39583958 }
39593959}
39603960
3961+ /// A buffer that can tell how much has been written to it already
3962+ ///
3963+ /// This is commonly used for when a buffer is passed and the user may not write past a
3964+ /// given size. It allows the user of such a buffer to know the current cursor position in
3965+ /// the buffer. The maximum write size is usually passed in the same unit as
3966+ /// [`BufLen::len`]: bytes since the buffer start.
3967+ pub ( crate ) trait BufLen {
3968+ /// Returns the number of bytes written into the buffer so far
3969+ fn len ( & self ) -> usize ;
3970+ }
3971+
3972+ impl BufLen for Vec < u8 > {
3973+ fn len ( & self ) -> usize {
3974+ self . len ( )
3975+ }
3976+ }
3977+
39613978#[ cfg( test) ]
39623979mod tests {
39633980 use super :: * ;
0 commit comments