From fb4dd2e0b3f7bdbe332e34970ce89260315e6434 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Thu, 13 Jul 2017 12:17:06 -0700 Subject: [PATCH] improve docs around Body type --- src/body.rs | 15 ++++++++++----- src/request.rs | 8 ++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/body.rs b/src/body.rs index 9cc1606..1b55f49 100644 --- a/src/body.rs +++ b/src/body.rs @@ -7,7 +7,13 @@ use hyper::{self, Chunk}; use {async_impl, wait}; -/// Body type for a request. +/// The body of a `Request`. +/// +/// In most cases, this is not needed directly, as the +/// [`RequestBuilder.body`][builder] method uses `Into`, which allows +/// passing many things (like a string or vector of bytes). +/// +/// [builder]: ./struct.RequestBuilder.html#method.body #[derive(Debug)] pub struct Body { reader: Kind, @@ -52,10 +58,9 @@ impl Body { } } - /// Create a `Body` from a `Reader` where we can predict the size in - /// advance, but where we don't want to load the data in memory. This - /// is useful if we need to ensure `Content-Length` is passed with the - /// request. + /// Create a `Body` from a `Read` where the size is known in advance + /// advance, but the data should not be loaded in full to memory. This will + /// set the `Content-Length` header, and stream from the `Read`. /// /// ```rust /// # use std::fs::File; diff --git a/src/request.rs b/src/request.rs index 6def7bb..a0353f1 100644 --- a/src/request.rs +++ b/src/request.rs @@ -156,6 +156,10 @@ impl RequestBuilder { /// Set the request body. /// + /// # Examples + /// + /// Using a string: + /// /// ```rust /// # fn run() -> Result<(), Box<::std::error::Error>> { /// let client = reqwest::Client::new()?; @@ -166,6 +170,8 @@ impl RequestBuilder { /// # } /// ``` /// + /// Using a `File`: + /// /// ```rust /// # use std::fs; /// # fn run() -> Result<(), Box<::std::error::Error>> { @@ -178,6 +184,8 @@ impl RequestBuilder { /// # } /// ``` /// + /// Using arbitrary bytes: + /// /// ```rust /// # use std::fs; /// # fn run() -> Result<(), Box<::std::error::Error>> {