From 26e202a0deb34acb7142e16d7c3cfa9f21c17221 Mon Sep 17 00:00:00 2001 From: Selwyn Date: Tue, 3 Apr 2018 20:31:15 +0200 Subject: [PATCH] Add code example structure explanation (#280) Clarify code example structure in combination with the `?` operator. Add as separate section so it can be easily removed when `?` can be used inside of `main`. Closes #275 --- src/lib.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 8a7d2bb..18a13d3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,6 +25,25 @@ //! applications that only require a few HTTP requests, and wish to handle //! them synchronously. //! +//! ## Code example structure +//! Note that all the following examples expect to be run outside of `main` because `?` is used. Like so: +//! +//! ```rust +//! use reqwest::{Error, Response}; +//! +//! fn run() -> Result<(), Error> { +//! let body = reqwest::get("https://www.rust-lang.org")? +//! .text()?; +//! +//! println!("body = {:?}", body); +//! Ok(()) +//! } +//! +//! fn main() { +//! run(); +//! } +//! ``` +//! //! ## Making a GET request //! //! For a single request, you can use the [`get`][get] shortcut method.