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
This commit is contained in:
Selwyn
2018-04-03 20:31:15 +02:00
committed by Sean McArthur
parent cf949177de
commit 26e202a0de

View File

@@ -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.