@@ -14,6 +14,7 @@ mod message_body;
14
14
mod size;
15
15
mod sized_stream;
16
16
17
+ #[ allow( deprecated) ]
17
18
pub use self :: body:: { AnyBody , Body , BoxBody } ;
18
19
pub use self :: body_stream:: BodyStream ;
19
20
pub use self :: message_body:: MessageBody ;
@@ -76,20 +77,20 @@ mod tests {
76
77
77
78
use super :: * ;
78
79
79
- impl Body {
80
+ impl AnyBody {
80
81
pub ( crate ) fn get_ref ( & self ) -> & [ u8 ] {
81
82
match * self {
82
- Body :: Bytes ( ref bin) => bin,
83
+ AnyBody :: Bytes ( ref bin) => bin,
83
84
_ => panic ! ( ) ,
84
85
}
85
86
}
86
87
}
87
88
88
89
#[ actix_rt:: test]
89
90
async fn test_static_str ( ) {
90
- assert_eq ! ( Body :: from( "" ) . size( ) , BodySize :: Sized ( 0 ) ) ;
91
- assert_eq ! ( Body :: from( "test" ) . size( ) , BodySize :: Sized ( 4 ) ) ;
92
- assert_eq ! ( Body :: from( "test" ) . get_ref( ) , b"test" ) ;
91
+ assert_eq ! ( AnyBody :: from( "" ) . size( ) , BodySize :: Sized ( 0 ) ) ;
92
+ assert_eq ! ( AnyBody :: from( "test" ) . size( ) , BodySize :: Sized ( 4 ) ) ;
93
+ assert_eq ! ( AnyBody :: from( "test" ) . get_ref( ) , b"test" ) ;
93
94
94
95
assert_eq ! ( "test" . size( ) , BodySize :: Sized ( 4 ) ) ;
95
96
assert_eq ! (
@@ -103,13 +104,16 @@ mod tests {
103
104
104
105
#[ actix_rt:: test]
105
106
async fn test_static_bytes ( ) {
106
- assert_eq ! ( Body :: from( b"test" . as_ref( ) ) . size( ) , BodySize :: Sized ( 4 ) ) ;
107
- assert_eq ! ( Body :: from( b"test" . as_ref( ) ) . get_ref( ) , b"test" ) ;
107
+ assert_eq ! ( AnyBody :: from( b"test" . as_ref( ) ) . size( ) , BodySize :: Sized ( 4 ) ) ;
108
+ assert_eq ! ( AnyBody :: from( b"test" . as_ref( ) ) . get_ref( ) , b"test" ) ;
108
109
assert_eq ! (
109
- Body :: copy_from_slice( b"test" . as_ref( ) ) . size( ) ,
110
+ AnyBody :: copy_from_slice( b"test" . as_ref( ) ) . size( ) ,
110
111
BodySize :: Sized ( 4 )
111
112
) ;
112
- assert_eq ! ( Body :: copy_from_slice( b"test" . as_ref( ) ) . get_ref( ) , b"test" ) ;
113
+ assert_eq ! (
114
+ AnyBody :: copy_from_slice( b"test" . as_ref( ) ) . get_ref( ) ,
115
+ b"test"
116
+ ) ;
113
117
let sb = Bytes :: from ( & b"test" [ ..] ) ;
114
118
pin ! ( sb) ;
115
119
@@ -122,8 +126,8 @@ mod tests {
122
126
123
127
#[ actix_rt:: test]
124
128
async fn test_vec ( ) {
125
- assert_eq ! ( Body :: from( Vec :: from( "test" ) ) . size( ) , BodySize :: Sized ( 4 ) ) ;
126
- assert_eq ! ( Body :: from( Vec :: from( "test" ) ) . get_ref( ) , b"test" ) ;
129
+ assert_eq ! ( AnyBody :: from( Vec :: from( "test" ) ) . size( ) , BodySize :: Sized ( 4 ) ) ;
130
+ assert_eq ! ( AnyBody :: from( Vec :: from( "test" ) ) . get_ref( ) , b"test" ) ;
127
131
let test_vec = Vec :: from ( "test" ) ;
128
132
pin ! ( test_vec) ;
129
133
@@ -140,8 +144,8 @@ mod tests {
140
144
#[ actix_rt:: test]
141
145
async fn test_bytes ( ) {
142
146
let b = Bytes :: from ( "test" ) ;
143
- assert_eq ! ( Body :: from( b. clone( ) ) . size( ) , BodySize :: Sized ( 4 ) ) ;
144
- assert_eq ! ( Body :: from( b. clone( ) ) . get_ref( ) , b"test" ) ;
147
+ assert_eq ! ( AnyBody :: from( b. clone( ) ) . size( ) , BodySize :: Sized ( 4 ) ) ;
148
+ assert_eq ! ( AnyBody :: from( b. clone( ) ) . get_ref( ) , b"test" ) ;
145
149
pin ! ( b) ;
146
150
147
151
assert_eq ! ( b. size( ) , BodySize :: Sized ( 4 ) ) ;
@@ -154,8 +158,8 @@ mod tests {
154
158
#[ actix_rt:: test]
155
159
async fn test_bytes_mut ( ) {
156
160
let b = BytesMut :: from ( "test" ) ;
157
- assert_eq ! ( Body :: from( b. clone( ) ) . size( ) , BodySize :: Sized ( 4 ) ) ;
158
- assert_eq ! ( Body :: from( b. clone( ) ) . get_ref( ) , b"test" ) ;
161
+ assert_eq ! ( AnyBody :: from( b. clone( ) ) . size( ) , BodySize :: Sized ( 4 ) ) ;
162
+ assert_eq ! ( AnyBody :: from( b. clone( ) ) . get_ref( ) , b"test" ) ;
159
163
pin ! ( b) ;
160
164
161
165
assert_eq ! ( b. size( ) , BodySize :: Sized ( 4 ) ) ;
@@ -168,10 +172,10 @@ mod tests {
168
172
#[ actix_rt:: test]
169
173
async fn test_string ( ) {
170
174
let b = "test" . to_owned ( ) ;
171
- assert_eq ! ( Body :: from( b. clone( ) ) . size( ) , BodySize :: Sized ( 4 ) ) ;
172
- assert_eq ! ( Body :: from( b. clone( ) ) . get_ref( ) , b"test" ) ;
173
- assert_eq ! ( Body :: from( & b) . size( ) , BodySize :: Sized ( 4 ) ) ;
174
- assert_eq ! ( Body :: from( & b) . get_ref( ) , b"test" ) ;
175
+ assert_eq ! ( AnyBody :: from( b. clone( ) ) . size( ) , BodySize :: Sized ( 4 ) ) ;
176
+ assert_eq ! ( AnyBody :: from( b. clone( ) ) . get_ref( ) , b"test" ) ;
177
+ assert_eq ! ( AnyBody :: from( & b) . size( ) , BodySize :: Sized ( 4 ) ) ;
178
+ assert_eq ! ( AnyBody :: from( & b) . get_ref( ) , b"test" ) ;
175
179
pin ! ( b) ;
176
180
177
181
assert_eq ! ( b. size( ) , BodySize :: Sized ( 4 ) ) ;
@@ -204,29 +208,33 @@ mod tests {
204
208
#[ actix_rt:: test]
205
209
async fn test_body_eq ( ) {
206
210
assert ! (
207
- Body :: Bytes ( Bytes :: from_static( b"1" ) )
208
- == Body :: Bytes ( Bytes :: from_static( b"1" ) )
211
+ AnyBody :: Bytes ( Bytes :: from_static( b"1" ) )
212
+ == AnyBody :: Bytes ( Bytes :: from_static( b"1" ) )
209
213
) ;
210
- assert ! ( Body :: Bytes ( Bytes :: from_static( b"1" ) ) != Body :: None ) ;
214
+ assert ! ( AnyBody :: Bytes ( Bytes :: from_static( b"1" ) ) != AnyBody :: None ) ;
211
215
}
212
216
213
217
#[ actix_rt:: test]
214
218
async fn test_body_debug ( ) {
215
- assert ! ( format!( "{:?}" , Body :: None ) . contains( "Body::None" ) ) ;
216
- assert ! ( format!( "{:?}" , Body :: Bytes ( Bytes :: from_static( b"1" ) ) ) . contains( '1' ) ) ;
219
+ assert ! ( format!( "{:?}" , AnyBody :: < BoxBody > :: None ) . contains( "Body::None" ) ) ;
220
+ assert ! ( format!( "{:?}" , AnyBody :: from ( Bytes :: from_static( b"1" ) ) ) . contains( '1' ) ) ;
217
221
}
218
222
219
223
#[ actix_rt:: test]
220
224
async fn test_serde_json ( ) {
221
225
use serde_json:: { json, Value } ;
222
226
assert_eq ! (
223
- Body :: from( serde_json:: to_vec( & Value :: String ( "test" . to_owned( ) ) ) . unwrap( ) )
224
- . size( ) ,
227
+ AnyBody :: from(
228
+ serde_json:: to_vec( & Value :: String ( "test" . to_owned( ) ) ) . unwrap( )
229
+ )
230
+ . size( ) ,
225
231
BodySize :: Sized ( 6 )
226
232
) ;
227
233
assert_eq ! (
228
- Body :: from( serde_json:: to_vec( & json!( { "test-key" : "test-value" } ) ) . unwrap( ) )
229
- . size( ) ,
234
+ AnyBody :: from(
235
+ serde_json:: to_vec( & json!( { "test-key" : "test-value" } ) ) . unwrap( )
236
+ )
237
+ . size( ) ,
230
238
BodySize :: Sized ( 25 )
231
239
) ;
232
240
}
@@ -250,11 +258,11 @@ mod tests {
250
258
251
259
#[ actix_rt:: test]
252
260
async fn test_to_bytes ( ) {
253
- let body = Body :: empty ( ) ;
261
+ let body = AnyBody :: empty ( ) ;
254
262
let bytes = to_bytes ( body) . await . unwrap ( ) ;
255
263
assert ! ( bytes. is_empty( ) ) ;
256
264
257
- let body = Body :: Bytes ( Bytes :: from_static ( b"123" ) ) ;
265
+ let body = AnyBody :: copy_from_slice ( b"123" ) ;
258
266
let bytes = to_bytes ( body) . await . unwrap ( ) ;
259
267
assert_eq ! ( bytes, b"123" [ ..] ) ;
260
268
}
0 commit comments