File tree 2 files changed +16
-5
lines changed
2 files changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ use std::{
4
4
task:: { Context , Poll } ,
5
5
} ;
6
6
7
- use bytes:: { Buf , Bytes } ;
7
+ use bytes:: { Buf , Bytes , BytesMut } ;
8
8
use http:: HeaderMap ;
9
9
use http_body:: { Body , Frame } ;
10
10
@@ -38,6 +38,11 @@ impl<B: Buf> Collected<B> {
38
38
self . bufs . copy_to_bytes ( self . bufs . remaining ( ) )
39
39
}
40
40
41
+ /// Convert this body into a [`BytesMut`].
42
+ pub fn to_bytes_mut ( mut self ) -> BytesMut {
43
+ self . bufs . copy_to_bytes_mut ( self . bufs . remaining ( ) )
44
+ }
45
+
41
46
pub ( crate ) fn push_frame ( & mut self , frame : Frame < B > ) {
42
47
let frame = match frame. into_data ( ) {
43
48
Ok ( data) => {
Original file line number Diff line number Diff line change @@ -19,6 +19,14 @@ impl<T: Buf> BufList<T> {
19
19
pub ( crate ) fn pop ( & mut self ) -> Option < T > {
20
20
self . bufs . pop_front ( )
21
21
}
22
+
23
+ #[ inline]
24
+ pub ( crate ) fn copy_to_bytes_mut ( & mut self , len : usize ) -> BytesMut {
25
+ assert ! ( len <= self . remaining( ) , "`len` greater than remaining" ) ;
26
+ let mut bm = BytesMut :: with_capacity ( len) ;
27
+ bm. put ( self . take ( len) ) ;
28
+ bm
29
+ }
22
30
}
23
31
24
32
impl < T : Buf > Buf for BufList < T > {
@@ -77,10 +85,8 @@ impl<T: Buf> Buf for BufList<T> {
77
85
}
78
86
Some ( front) if front. remaining ( ) > len => front. copy_to_bytes ( len) ,
79
87
_ => {
80
- assert ! ( len <= self . remaining( ) , "`len` greater than remaining" ) ;
81
- let mut bm = BytesMut :: with_capacity ( len) ;
82
- bm. put ( self . take ( len) ) ;
83
- bm. freeze ( )
88
+ let bytes_mut = self . copy_to_bytes_mut ( len) ;
89
+ bytes_mut. freeze ( )
84
90
}
85
91
}
86
92
}
You can’t perform that action at this time.
0 commit comments