@@ -98,7 +98,7 @@ impl Response {
98
98
/// ```
99
99
/// # fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
100
100
/// #
101
- /// use http_types::{Url, Method, Response, StatusCode};
101
+ /// use http_types::{Method, Response, StatusCode, Url };
102
102
///
103
103
/// let mut req = Response::new(StatusCode::Ok);
104
104
/// req.insert_header("Content-Type", "text/plain");
@@ -115,8 +115,9 @@ impl Response {
115
115
116
116
/// Append a header to the headers.
117
117
///
118
- /// Unlike `insert` this function will not override the contents of a header, but insert a
119
- /// header if there aren't any. Or else append to the existing list of headers.
118
+ /// Unlike `insert` this function will not override the contents of a
119
+ /// header, but insert a header if there aren't any. Or else append to
120
+ /// the existing list of headers.
120
121
///
121
122
/// # Examples
122
123
///
@@ -161,7 +162,7 @@ impl Response {
161
162
/// # fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
162
163
/// # async_std::task::block_on(async {
163
164
/// #
164
- /// use http_types::{Body, Url, Method, Response, StatusCode};
165
+ /// use http_types::{Body, Method, Response, StatusCode, Url };
165
166
///
166
167
/// let mut req = Response::new(StatusCode::Ok);
167
168
/// req.set_body("Hello, Nori!");
@@ -190,7 +191,7 @@ impl Response {
190
191
/// # fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
191
192
/// # async_std::task::block_on(async {
192
193
/// #
193
- /// use http_types::{Body, Url, Method, Response, StatusCode};
194
+ /// use http_types::{Body, Method, Response, StatusCode, Url };
194
195
///
195
196
/// let mut req = Response::new(StatusCode::Ok);
196
197
/// req.set_body("Hello, Nori!");
@@ -218,7 +219,7 @@ impl Response {
218
219
/// # fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
219
220
/// # async_std::task::block_on(async {
220
221
/// #
221
- /// use http_types::{Body, Url, Method, Response, StatusCode};
222
+ /// use http_types::{Body, Method, Response, StatusCode, Url };
222
223
///
223
224
/// let mut req = Response::new(StatusCode::Ok);
224
225
/// req.set_body("Hello, Nori!");
@@ -251,10 +252,10 @@ impl Response {
251
252
/// # use std::io::prelude::*;
252
253
/// # fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
253
254
/// # async_std::task::block_on(async {
254
- /// use http_types::{Body, Url, Method, Response, StatusCode};
255
255
/// use async_std::io::Cursor;
256
+ /// use http_types::{Body, Method, Response, StatusCode, Url};
256
257
///
257
- /// let mut res = Response::new(StatusCode::Ok);
258
+ /// let mut res = Response::new(StatusCode::Ok);
258
259
/// let cursor = Cursor::new("Hello Nori");
259
260
/// let body = Body::from_reader(cursor, None);
260
261
/// res.set_body(body);
@@ -277,7 +278,7 @@ impl Response {
277
278
///
278
279
/// ```
279
280
/// # fn main() -> Result<(), http_types::Error> { async_std::task::block_on(async {
280
- /// use http_types::{Body, Url, Method, Response, StatusCode};
281
+ /// use http_types::{Body, Method, Response, StatusCode, Url };
281
282
///
282
283
/// let bytes = vec![1, 2, 3];
283
284
/// let mut res = Response::new(StatusCode::Ok);
@@ -303,14 +304,18 @@ impl Response {
303
304
///
304
305
/// ```
305
306
/// # fn main() -> Result<(), http_types::Error> { async_std::task::block_on(async {
306
- /// use http_types::{Body, Url, Method, Response, StatusCode};
307
- /// use http_types::convert::{Serialize, Deserialize };
307
+ /// use http_types::convert::{Deserialize, Serialize};
308
+ /// use http_types::{Body, Method, Response, StatusCode, Url };
308
309
///
309
310
/// #[derive(Debug, Serialize, Deserialize)]
310
- /// struct Cat { name: String }
311
+ /// struct Cat {
312
+ /// name: String,
313
+ /// }
311
314
///
312
- /// let cat = Cat { name: String::from("chashu") };
313
- /// let mut res = Response::new(StatusCode::Ok);
315
+ /// let cat = Cat {
316
+ /// name: String::from("chashu"),
317
+ /// };
318
+ /// let mut res = Response::new(StatusCode::Ok);
314
319
/// res.set_body(Body::from_json(&cat)?);
315
320
///
316
321
/// let cat: Cat = res.body_json().await?;
@@ -333,14 +338,18 @@ impl Response {
333
338
///
334
339
/// ```
335
340
/// # fn main() -> Result<(), http_types::Error> { async_std::task::block_on(async {
336
- /// use http_types::{Body, Url, Method, Response, StatusCode};
337
- /// use http_types::convert::{Serialize, Deserialize };
341
+ /// use http_types::convert::{Deserialize, Serialize};
342
+ /// use http_types::{Body, Method, Response, StatusCode, Url };
338
343
///
339
344
/// #[derive(Debug, Serialize, Deserialize)]
340
- /// struct Cat { name: String }
345
+ /// struct Cat {
346
+ /// name: String,
347
+ /// }
341
348
///
342
- /// let cat = Cat { name: String::from("chashu") };
343
- /// let mut res = Response::new(StatusCode::Ok);
349
+ /// let cat = Cat {
350
+ /// name: String::from("chashu"),
351
+ /// };
352
+ /// let mut res = Response::new(StatusCode::Ok);
344
353
/// res.set_body(Body::from_form(&cat)?);
345
354
///
346
355
/// let cat: Cat = res.body_form().await?;
@@ -374,14 +383,16 @@ impl Response {
374
383
375
384
/// Get the length of the body stream, if it has been set.
376
385
///
377
- /// This value is set when passing a fixed-size object into as the body. E.g. a string, or a
378
- /// buffer. Consumers of this API should check this value to decide whether to use `Chunked`
379
- /// encoding, or set the response length.
386
+ /// This value is set when passing a fixed-size object into as the body.
387
+ /// E.g. a string, or a buffer. Consumers of this API should check this
388
+ /// value to decide whether to use `Chunked` encoding, or set the
389
+ /// response length.
380
390
pub fn len ( & self ) -> Option < usize > {
381
391
self . body . len ( )
382
392
}
383
393
384
- /// Returns `true` if the set length of the body stream is zero, `false` otherwise.
394
+ /// Returns `true` if the set length of the body stream is zero, `false`
395
+ /// otherwise.
385
396
pub fn is_empty ( & self ) -> Option < bool > {
386
397
self . body . is_empty ( )
387
398
}
@@ -426,7 +437,8 @@ impl Response {
426
437
self . peer_addr . as_deref ( )
427
438
}
428
439
429
- /// Get the local socket address for the underlying transport, if appropriate
440
+ /// Get the local socket address for the underlying transport, if
441
+ /// appropriate
430
442
pub fn local_addr ( & self ) -> Option < & str > {
431
443
self . local_addr . as_deref ( )
432
444
}
@@ -477,8 +489,8 @@ impl Response {
477
489
self . headers . iter ( )
478
490
}
479
491
480
- /// An iterator visiting all header pairs in arbitrary order, with mutable references to the
481
- /// values.
492
+ /// An iterator visiting all header pairs in arbitrary order, with mutable
493
+ /// references to the values.
482
494
pub fn iter_mut ( & mut self ) -> headers:: IterMut < ' _ > {
483
495
self . headers . iter_mut ( )
484
496
}
@@ -506,7 +518,7 @@ impl Response {
506
518
/// ```
507
519
/// # fn main() -> Result<(), http_types::Error> {
508
520
/// #
509
- /// use http_types::{StatusCode, Response , Version};
521
+ /// use http_types::{Response, StatusCode , Version};
510
522
///
511
523
/// let mut res = Response::new(StatusCode::Ok);
512
524
/// res.ext_mut().insert("hello from the extension");
@@ -520,7 +532,8 @@ impl Response {
520
532
}
521
533
522
534
impl Clone for Response {
523
- /// Clone the response, resolving the body to `Body::empty()` and removing extensions.
535
+ /// Clone the response, resolving the body to `Body::empty()` and removing
536
+ /// extensions.
524
537
fn clone ( & self ) -> Self {
525
538
Self {
526
539
status : self . status . clone ( ) ,
0 commit comments