Skip to content

Commit 64541a6

Browse files
author
zeroed
committed
Rust FMT in Request
1 parent 7e06db5 commit 64541a6

File tree

1 file changed

+54
-37
lines changed

1 file changed

+54
-37
lines changed

src/request.rs

Lines changed: 54 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ impl Request {
156156
/// ```
157157
/// # fn main() -> Result<(), http_types::Error> {
158158
/// #
159-
/// use http_types::{Url, Method, Request, Response, StatusCode};
159+
/// use http_types::{Method, Request, Response, StatusCode, Url};
160160
/// let mut req = Request::new(Method::Get, Url::parse("https://example.com")?);
161161
/// assert_eq!(req.url().scheme(), "https");
162162
/// #
@@ -173,7 +173,7 @@ impl Request {
173173
/// ```
174174
/// # fn main() -> Result<(), http_types::Error> {
175175
/// #
176-
/// use http_types::{Url, Method, Request, Response, StatusCode};
176+
/// use http_types::{Method, Request, Response, StatusCode, Url};
177177
/// let mut req = Request::new(Method::Get, Url::parse("https://example.com")?);
178178
/// req.url_mut().set_scheme("http");
179179
/// assert_eq!(req.url().scheme(), "http");
@@ -189,7 +189,7 @@ impl Request {
189189
/// # Examples
190190
///
191191
/// ```
192-
/// use http_types::{Url, Method, Request};
192+
/// use http_types::{Method, Request, Url};
193193
///
194194
/// let mut req = Request::new(Method::Get, Url::parse("https://example.com").unwrap());
195195
/// req.set_body("Hello, Nori!");
@@ -208,7 +208,7 @@ impl Request {
208208
/// # fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
209209
/// # async_std::task::block_on(async {
210210
/// #
211-
/// use http_types::{Body, Url, Method, Request};
211+
/// use http_types::{Body, Method, Request, Url};
212212
///
213213
/// let mut req = Request::new(Method::Get, Url::parse("https://example.com").unwrap());
214214
/// req.set_body("Hello, Nori!");
@@ -235,7 +235,7 @@ impl Request {
235235
/// # fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
236236
/// # async_std::task::block_on(async {
237237
/// #
238-
/// use http_types::{Body, Url, Method, Request};
238+
/// use http_types::{Body, Method, Request, Url};
239239
///
240240
/// let mut req = Request::new(Method::Get, Url::parse("https://example.com").unwrap());
241241
/// req.set_body("Hello, Nori!");
@@ -262,7 +262,7 @@ impl Request {
262262
/// # fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
263263
/// # async_std::task::block_on(async {
264264
/// #
265-
/// use http_types::{Body, Url, Method, Request};
265+
/// use http_types::{Body, Method, Request, Url};
266266
///
267267
/// let mut req = Request::new(Method::Get, Url::parse("https://example.com").unwrap());
268268
/// req.set_body("Hello, Nori!");
@@ -295,8 +295,8 @@ impl Request {
295295
/// # use std::io::prelude::*;
296296
/// # fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
297297
/// # async_std::task::block_on(async {
298-
/// use http_types::{Body, Url, Method, Request};
299298
/// use async_std::io::Cursor;
299+
/// use http_types::{Body, Method, Request, Url};
300300
///
301301
/// let mut req = Request::new(Method::Get, Url::parse("https://example.com").unwrap());
302302
///
@@ -322,7 +322,7 @@ impl Request {
322322
///
323323
/// ```
324324
/// # fn main() -> Result<(), http_types::Error> { async_std::task::block_on(async {
325-
/// use http_types::{Body, Url, Method, Request};
325+
/// use http_types::{Body, Method, Request, Url};
326326
///
327327
/// let bytes = vec![1, 2, 3];
328328
/// let mut req = Request::new(Method::Get, Url::parse("https://example.com").unwrap());
@@ -348,13 +348,17 @@ impl Request {
348348
///
349349
/// ```
350350
/// # fn main() -> Result<(), http_types::Error> { async_std::task::block_on(async {
351-
/// use http_types::{Body, Url, Method, Request};
352-
/// use http_types::convert::{Serialize, Deserialize};
351+
/// use http_types::convert::{Deserialize, Serialize};
352+
/// use http_types::{Body, Method, Request, Url};
353353
///
354354
/// #[derive(Debug, Serialize, Deserialize)]
355-
/// struct Cat { name: String }
355+
/// struct Cat {
356+
/// name: String,
357+
/// }
356358
///
357-
/// let cat = Cat { name: String::from("chashu") };
359+
/// let cat = Cat {
360+
/// name: String::from("chashu"),
361+
/// };
358362
/// let mut req = Request::new(Method::Get, Url::parse("https://example.com").unwrap());
359363
/// req.set_body(Body::from_json(&cat)?);
360364
///
@@ -378,13 +382,17 @@ impl Request {
378382
///
379383
/// ```
380384
/// # fn main() -> Result<(), http_types::Error> { async_std::task::block_on(async {
381-
/// use http_types::{Body, Url, Method, Request};
382-
/// use http_types::convert::{Serialize, Deserialize};
385+
/// use http_types::convert::{Deserialize, Serialize};
386+
/// use http_types::{Body, Method, Request, Url};
383387
///
384388
/// #[derive(Debug, Serialize, Deserialize)]
385-
/// struct Cat { name: String }
389+
/// struct Cat {
390+
/// name: String,
391+
/// }
386392
///
387-
/// let cat = Cat { name: String::from("chashu") };
393+
/// let cat = Cat {
394+
/// name: String::from("chashu"),
395+
/// };
388396
/// let mut req = Request::new(Method::Get, Url::parse("https://example.com").unwrap());
389397
/// req.set_body(Body::from_form(&cat)?);
390398
///
@@ -419,7 +427,7 @@ impl Request {
419427
/// ```
420428
/// # fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
421429
/// #
422-
/// use http_types::{Url, Method, Request};
430+
/// use http_types::{Method, Request, Url};
423431
///
424432
/// let mut req = Request::new(Method::Get, Url::parse("https://example.com")?);
425433
/// req.insert_header("Content-Type", "text/plain");
@@ -436,15 +444,16 @@ impl Request {
436444

437445
/// Append a header to the headers.
438446
///
439-
/// Unlike `insert` this function will not override the contents of a header, but insert a
440-
/// header if there aren't any. Or else append to the existing list of headers.
447+
/// Unlike `insert` this function will not override the contents of a
448+
/// header, but insert a header if there aren't any. Or else append to
449+
/// the existing list of headers.
441450
///
442451
/// # Examples
443452
///
444453
/// ```
445454
/// # fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
446455
/// #
447-
/// use http_types::{Url, Method, Request};
456+
/// use http_types::{Method, Request, Url};
448457
///
449458
/// let mut req = Request::new(Method::Get, Url::parse("https://example.com")?);
450459
/// req.append_header("Content-Type", "text/plain");
@@ -478,14 +487,16 @@ impl Request {
478487

479488
/// Get the length of the body stream, if it has been set.
480489
///
481-
/// This value is set when passing a fixed-size object into as the body. E.g. a string, or a
482-
/// buffer. Consumers of this API should check this value to decide whether to use `Chunked`
483-
/// encoding, or set the response length.
490+
/// This value is set when passing a fixed-size object into as the body.
491+
/// E.g. a string, or a buffer. Consumers of this API should check this
492+
/// value to decide whether to use `Chunked` encoding, or set the
493+
/// response length.
484494
pub fn len(&self) -> Option<usize> {
485495
self.body.len()
486496
}
487497

488-
/// Returns `true` if the request has a set body stream length of zero, `false` otherwise.
498+
/// Returns `true` if the request has a set body stream length of zero,
499+
/// `false` otherwise.
489500
pub fn is_empty(&self) -> Option<bool> {
490501
self.body.is_empty()
491502
}
@@ -495,7 +506,7 @@ impl Request {
495506
/// # Examples
496507
///
497508
/// ```
498-
/// use http_types::{Url, Method, Request, Version};
509+
/// use http_types::{Method, Request, Url, Version};
499510
///
500511
/// # fn main() -> Result<(), http_types::Error> {
501512
/// #
@@ -516,7 +527,7 @@ impl Request {
516527
/// # Examples
517528
///
518529
/// ```
519-
/// use http_types::{Url, Method, Request, Version};
530+
/// use http_types::{Method, Request, Url, Version};
520531
///
521532
/// # fn main() -> Result<(), http_types::Error> {
522533
/// #
@@ -552,8 +563,8 @@ impl Request {
552563
self.headers.iter()
553564
}
554565

555-
/// An iterator visiting all header pairs in arbitrary order, with mutable references to the
556-
/// values.
566+
/// An iterator visiting all header pairs in arbitrary order, with mutable
567+
/// references to the values.
557568
pub fn iter_mut(&mut self) -> headers::IterMut<'_> {
558569
self.headers.iter_mut()
559570
}
@@ -580,7 +591,7 @@ impl Request {
580591
/// ```
581592
/// # fn main() -> Result<(), http_types::Error> {
582593
/// #
583-
/// use http_types::{Url, Method, Request, Version};
594+
/// use http_types::{Method, Request, Url, Version};
584595
///
585596
/// let mut req = Request::new(Method::Get, Url::parse("https://example.com")?);
586597
/// req.ext_mut().insert("hello from the extension");
@@ -599,15 +610,18 @@ impl Request {
599610
/// ```no_run
600611
/// # #[async_std::main]
601612
/// # async fn main() -> http_types::Result<()> {
602-
/// use http_types::{Url, Method, Request};
603-
/// use http_types::convert::{Serialize, Deserialize};
613+
/// use http_types::convert::{Deserialize, Serialize};
614+
/// use http_types::{Method, Request, Url};
604615
///
605616
/// #[derive(Serialize, Deserialize)]
606617
/// struct Index {
607-
/// page: u32
618+
/// page: u32,
608619
/// }
609620
///
610-
/// let req = Request::new(Method::Get, Url::parse("https://httpbin.org/get?page=2").unwrap());
621+
/// let req = Request::new(
622+
/// Method::Get,
623+
/// Url::parse("https://httpbin.org/get?page=2").unwrap(),
624+
/// );
611625
/// let Index { page } = req.query()?;
612626
/// assert_eq!(page, 2);
613627
/// # Ok(()) }
@@ -628,16 +642,19 @@ impl Request {
628642
/// ```no_run
629643
/// # #[async_std::main]
630644
/// # async fn main() -> http_types::Result<()> {
631-
/// use http_types::{Url, Method, Request};
632-
/// use http_types::convert::{Serialize, Deserialize};
645+
/// use http_types::convert::{Deserialize, Serialize};
646+
/// use http_types::{Method, Request, Url};
633647
///
634648
/// #[derive(Serialize, Deserialize)]
635649
/// struct Index {
636-
/// page: u32
650+
/// page: u32,
637651
/// }
638652
///
639653
/// let query = Index { page: 2 };
640-
/// let mut req = Request::new(Method::Get, Url::parse("https://httpbin.org/get?page=2").unwrap());
654+
/// let mut req = Request::new(
655+
/// Method::Get,
656+
/// Url::parse("https://httpbin.org/get?page=2").unwrap(),
657+
/// );
641658
/// req.set_query(&query)?;
642659
/// assert_eq!(req.url().query(), Some("page=2"));
643660
/// assert_eq!(req.url().as_str(), "https://httpbin.org/get?page=2");

0 commit comments

Comments
 (0)