@@ -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 ;
@@ -755,7 +755,7 @@ impl Connection {
755755 self . receiving_ecn ,
756756 & mut SentFrames :: default ( ) ,
757757 & mut self . spaces [ space_id] ,
758- buf . buf ,
758+ & mut buf,
759759 & mut self . stats ,
760760 ) ;
761761 }
@@ -842,7 +842,7 @@ impl Connection {
842842 let sent = self . populate_packet (
843843 now,
844844 space_id,
845- buf . buf ,
845+ & mut buf,
846846 builder. max_size ,
847847 builder. exact_number ,
848848 ) ;
@@ -3020,7 +3020,7 @@ impl Connection {
30203020 & mut self ,
30213021 now : Instant ,
30223022 space_id : SpaceId ,
3023- buf : & mut Vec < u8 > ,
3023+ buf : & mut ( impl BufMut + BufLen ) ,
30243024 max_size : usize ,
30253025 pn : u64 ,
30263026 ) -> SentFrames {
@@ -3286,7 +3286,7 @@ impl Connection {
32863286 receiving_ecn : bool ,
32873287 sent : & mut SentFrames ,
32883288 space : & mut PacketSpace ,
3289- buf : & mut Vec < u8 > ,
3289+ buf : & mut impl BufMut ,
32903290 stats : & mut ConnectionStats ,
32913291 ) {
32923292 debug_assert ! ( !space. pending_acks. ranges( ) . is_empty( ) ) ;
@@ -3963,6 +3963,23 @@ fn negotiate_max_idle_timeout(x: Option<VarInt>, y: Option<VarInt>) -> Option<Du
39633963 }
39643964}
39653965
3966+ /// A buffer that can tell how much has been written to it already
3967+ ///
3968+ /// This is commonly used for when a buffer is passed and the user may not write past a
3969+ /// given size. It allows the user of such a buffer to know the current cursor position in
3970+ /// the buffer. The maximum write size is usually passed in the same unit as
3971+ /// [`BufLen::len`]: bytes since the buffer start.
3972+ pub ( crate ) trait BufLen {
3973+ /// Returns the number of bytes written into the buffer so far
3974+ fn len ( & self ) -> usize ;
3975+ }
3976+
3977+ impl BufLen for Vec < u8 > {
3978+ fn len ( & self ) -> usize {
3979+ self . len ( )
3980+ }
3981+ }
3982+
39663983#[ cfg( test) ]
39673984mod tests {
39683985 use super :: * ;
0 commit comments