Silence warnings during testing.

This commit is contained in:
Sergio Benitez 2017-02-02 02:16:21 -08:00
parent 7b8d104ae0
commit a9c3b8a919
28 changed files with 92 additions and 23 deletions

View File

@ -42,8 +42,11 @@ fn user_page(username: &str) -> String {
format!("This is {}'s page.", username) format!("This is {}'s page.", username)
} }
fn main() { pub fn rocket() -> rocket::Rocket {
rocket::ignite() rocket::ignite()
.mount("/", routes![files::index, files::files, user_page, login]) .mount("/", routes![files::index, files::files, user_page, login])
.launch(); }
fn main() {
rocket().launch()
} }

View File

@ -1,11 +1,12 @@
use super::rocket;
use rocket::testing::MockRequest; use rocket::testing::MockRequest;
use rocket::http::Method::*; use rocket::http::Method::*;
use rocket::http::{ContentType, Status}; use rocket::http::{ContentType, Status};
use super::rocket;
fn test_login(username: &str, password: &str, age: isize, status: Status, fn test_login(username: &str, password: &str, age: isize, status: Status,
body: Option<&'static str>) { body: Option<&'static str>) {
let rocket = rocket::ignite().mount("/", routes![super::user_page, super::login]); let rocket = rocket();
let mut req = MockRequest::new(Post, "/login") let mut req = MockRequest::new(Post, "/login")
.header(ContentType::Form) .header(ContentType::Form)
.body(&format!("username={}&password={}&age={}", username, password, age)); .body(&format!("username={}&password={}&age={}", username, password, age));
@ -38,12 +39,12 @@ fn test_bad_login() {
} }
fn check_bad_form(form_str: &str, status: Status) { fn check_bad_form(form_str: &str, status: Status) {
let rocket = rocket::ignite().mount("/", routes![super::user_page, super::login]); let rocket = rocket();
let mut req = MockRequest::new(Post, "/login") let mut req = MockRequest::new(Post, "/login")
.header(ContentType::Form) .header(ContentType::Form)
.body(form_str); .body(form_str);
let mut response = req.dispatch_with(&rocket); let response = req.dispatch_with(&rocket);
assert_eq!(response.status(), status); assert_eq!(response.status(), status);
} }

View File

@ -6,6 +6,7 @@ use self::schema::tasks::dsl::{tasks as all_tasks, completed as task_completed};
const DATABASE_FILE: &'static str = env!("DATABASE_URL"); const DATABASE_FILE: &'static str = env!("DATABASE_URL");
#[allow(dead_code)]
mod schema { mod schema {
infer_schema!("env:DATABASE_URL"); infer_schema!("env:DATABASE_URL");
} }

View File

@ -76,6 +76,7 @@ impl Catcher {
/// # Examples /// # Examples
/// ///
/// ```rust /// ```rust
/// # #![allow(unused_variables)]
/// use rocket::{Catcher, Request, Error}; /// use rocket::{Catcher, Request, Error};
/// use rocket::response::{Result, Responder}; /// use rocket::response::{Result, Responder};
/// ///

View File

@ -225,7 +225,7 @@ impl Config {
/// # Example /// # Example
/// ///
/// ```rust /// ```rust
/// use rocket::config::{Config, Environment, Value}; /// use rocket::config::{Config, Environment};
/// ///
/// // Create a new config with a session key. /// // Create a new config with a session key.
/// let key = "adL5fFIPmZBrlyHk2YT4NLV3YCk2gFXz"; /// let key = "adL5fFIPmZBrlyHk2YT4NLV3YCk2gFXz";

View File

@ -132,6 +132,7 @@
//! //!
//! const DEFAULT_TEMPLATE_DIR: &'static str = "templates"; //! const DEFAULT_TEMPLATE_DIR: &'static str = "templates";
//! //!
//! # #[allow(unused_variables)]
//! let template_dir = config::active().map(|config| { //! let template_dir = config::active().map(|config| {
//! let dir = config.get_str("template_dir") //! let dir = config.get_str("template_dir")
//! .map_err(|e| if !e.is_not_found() { e.pretty_print(); }) //! .map_err(|e| if !e.is_not_found() { e.pretty_print(); })

View File

@ -59,6 +59,7 @@ impl<'a, S, E> IntoOutcome<S, (Status, E), Data> for Result<S, E> {
/// Say that you have a custom type, `Person`: /// Say that you have a custom type, `Person`:
/// ///
/// ```rust /// ```rust
/// # #[allow(dead_code)]
/// struct Person { /// struct Person {
/// name: String, /// name: String,
/// age: u16 /// age: u16
@ -80,6 +81,8 @@ impl<'a, S, E> IntoOutcome<S, (Status, E), Data> for Result<S, E> {
/// A `FromData` implementation allowing this looks like: /// A `FromData` implementation allowing this looks like:
/// ///
/// ```rust /// ```rust
/// # #![allow(unused_attributes)]
/// # #![allow(unused_variables)]
/// # #![feature(plugin)] /// # #![feature(plugin)]
/// # #![plugin(rocket_codegen)] /// # #![plugin(rocket_codegen)]
/// # extern crate rocket; /// # extern crate rocket;
@ -118,7 +121,7 @@ impl<'a, S, E> IntoOutcome<S, (Status, E), Data> for Result<S, E> {
/// // Parse the age. /// // Parse the age.
/// let age: u16 = match age.parse() { /// let age: u16 = match age.parse() {
/// Ok(age) => age, /// Ok(age) => age,
/// Err(e) => return Failure((Status::BadRequest, "Bad age.".into())) /// Err(_) => return Failure((Status::BadRequest, "Bad age.".into()))
/// }; /// };
/// ///
/// // Return successfully. /// // Return successfully.

View File

@ -22,6 +22,7 @@ use http::ascii::{uncased_eq, UncasedAscii};
/// ```rust /// ```rust
/// use rocket::http::ContentType; /// use rocket::http::ContentType;
/// ///
/// # #[allow(unused_variables)]
/// let html = ContentType::HTML; /// let html = ContentType::HTML;
/// ``` /// ```
/// ///
@ -34,6 +35,7 @@ use http::ascii::{uncased_eq, UncasedAscii};
/// use rocket::http::ContentType; /// use rocket::http::ContentType;
/// use rocket::response::Response; /// use rocket::response::Response;
/// ///
/// # #[allow(unused_variables)]
/// let response = Response::build().header(ContentType::HTML).finalize(); /// let response = Response::build().header(ContentType::HTML).finalize();
/// ``` /// ```
#[derive(Debug, Clone, PartialEq, Hash)] #[derive(Debug, Clone, PartialEq, Hash)]

View File

@ -167,7 +167,7 @@ impl<'h> HeaderMap<'h> {
/// # Example /// # Example
/// ///
/// ```rust /// ```rust
/// use rocket::http::{HeaderMap, ContentType}; /// use rocket::http::HeaderMap;
/// ///
/// let map = HeaderMap::new(); /// let map = HeaderMap::new();
/// assert!(map.is_empty()); /// assert!(map.is_empty());
@ -183,7 +183,7 @@ impl<'h> HeaderMap<'h> {
/// # Example /// # Example
/// ///
/// ```rust /// ```rust
/// use rocket::http::{HeaderMap, ContentType}; /// use rocket::http::HeaderMap;
/// ///
/// let mut map = HeaderMap::new(); /// let mut map = HeaderMap::new();
/// map.add_raw("X-Custom", "value_1"); /// map.add_raw("X-Custom", "value_1");
@ -212,7 +212,7 @@ impl<'h> HeaderMap<'h> {
/// Retrieve the first value when one exists: /// Retrieve the first value when one exists:
/// ///
/// ```rust /// ```rust
/// use rocket::http::{HeaderMap, ContentType}; /// use rocket::http::HeaderMap;
/// ///
/// let mut map = HeaderMap::new(); /// let mut map = HeaderMap::new();
/// map.add_raw("X-Custom", "value_1"); /// map.add_raw("X-Custom", "value_1");
@ -220,19 +220,19 @@ impl<'h> HeaderMap<'h> {
/// ///
/// assert_eq!(map.len(), 2); /// assert_eq!(map.len(), 2);
/// ///
/// let mut first_value = map.get_one("X-Custom"); /// let first_value = map.get_one("X-Custom");
/// assert_eq!(first_value, Some("value_1")); /// assert_eq!(first_value, Some("value_1"));
/// ``` /// ```
/// ///
/// Attempt to retrieve a value that doesn't exist: /// Attempt to retrieve a value that doesn't exist:
/// ///
/// ```rust /// ```rust
/// use rocket::http::{HeaderMap, ContentType}; /// use rocket::http::HeaderMap;
/// ///
/// let mut map = HeaderMap::new(); /// let mut map = HeaderMap::new();
/// map.add_raw("X-Custom", "value_1"); /// map.add_raw("X-Custom", "value_1");
/// ///
/// let mut first_value = map.get_one("X-Other"); /// let first_value = map.get_one("X-Other");
/// assert_eq!(first_value, None); /// assert_eq!(first_value, None);
/// ``` /// ```
#[inline] #[inline]

View File

@ -34,6 +34,7 @@ pub enum StatusClass {
/// ```rust /// ```rust
/// use rocket::http::Status; /// use rocket::http::Status;
/// ///
/// # #[allow(unused_variables)]
/// let ok = Status::Ok; /// let ok = Status::Ok;
/// ``` /// ```
/// ///
@ -42,6 +43,7 @@ pub enum StatusClass {
/// ```rust /// ```rust
/// use rocket::http::Status; /// use rocket::http::Status;
/// ///
/// # #[allow(unused_variables)]
/// let not_found = Status::NotFound; /// let not_found = Status::NotFound;
/// ``` /// ```
/// ///

View File

@ -303,7 +303,6 @@ unsafe impl<'a> Sync for URI<'a> { /* It's safe! */ }
/// ///
/// ```rust /// ```rust
/// use rocket::http::uri::URI; /// use rocket::http::uri::URI;
/// use rocket::http::uri::Segments;
/// ///
/// let uri = URI::new("/a/////b/c////////d"); /// let uri = URI::new("/a/////b/c////////d");
/// let segments = uri.segments(); /// let segments = uri.segments();

View File

@ -50,6 +50,7 @@
//! //!
//! ```rust //! ```rust
//! #![feature(plugin)] //! #![feature(plugin)]
//! # #![allow(unused_attributes)]
//! #![plugin(rocket_codegen)] //! #![plugin(rocket_codegen)]
//! //!
//! extern crate rocket; //! extern crate rocket;

View File

@ -10,6 +10,7 @@ use request::FormItems;
/// ```rust /// ```rust
/// #![feature(plugin, custom_derive)] /// #![feature(plugin, custom_derive)]
/// #![plugin(rocket_codegen)] /// #![plugin(rocket_codegen)]
/// # #![allow(deprecated, dead_code, unused_attributes)]
/// ///
/// extern crate rocket; /// extern crate rocket;
/// ///
@ -25,6 +26,7 @@ use request::FormItems;
/// ///
/// ```rust /// ```rust
/// # #![feature(plugin, custom_derive)] /// # #![feature(plugin, custom_derive)]
/// # #![allow(deprecated, dead_code, unused_attributes)]
/// # #![plugin(rocket_codegen)] /// # #![plugin(rocket_codegen)]
/// # extern crate rocket; /// # extern crate rocket;
/// # use rocket::request::Form; /// # use rocket::request::Form;

View File

@ -38,6 +38,7 @@ use http::uri::URI;
/// following structure: /// following structure:
/// ///
/// ```rust /// ```rust
/// # #[allow(dead_code)]
/// struct Person<'r> { /// struct Person<'r> {
/// name: String, /// name: String,
/// age: Result<u16, &'r str> /// age: Result<u16, &'r str>
@ -106,7 +107,6 @@ use http::uri::URI;
/// ///
/// ```rust /// ```rust
/// use rocket::request::FromFormValue; /// use rocket::request::FromFormValue;
/// use rocket::Error;
/// ///
/// struct AdultAge(usize); /// struct AdultAge(usize);
/// ///

View File

@ -69,6 +69,7 @@ use outcome::Outcome::*;
/// ///
/// ```rust /// ```rust
/// # #![feature(plugin, custom_derive)] /// # #![feature(plugin, custom_derive)]
/// # #![allow(deprecated, dead_code, unused_attributes)]
/// # #![plugin(rocket_codegen)] /// # #![plugin(rocket_codegen)]
/// # extern crate rocket; /// # extern crate rocket;
/// #[derive(FromForm)] /// #[derive(FromForm)]
@ -82,6 +83,7 @@ use outcome::Outcome::*;
/// ///
/// ```rust /// ```rust
/// # #![feature(plugin, custom_derive)] /// # #![feature(plugin, custom_derive)]
/// # #![allow(deprecated, unused_attributes)]
/// # #![plugin(rocket_codegen)] /// # #![plugin(rocket_codegen)]
/// # extern crate rocket; /// # extern crate rocket;
/// # use rocket::request::Form; /// # use rocket::request::Form;
@ -106,6 +108,7 @@ use outcome::Outcome::*;
/// ///
/// ```rust /// ```rust
/// # #![feature(plugin, custom_derive)] /// # #![feature(plugin, custom_derive)]
/// # #![allow(deprecated, dead_code, unused_attributes)]
/// # #![plugin(rocket_codegen)] /// # #![plugin(rocket_codegen)]
/// # extern crate rocket; /// # extern crate rocket;
/// #[derive(FromForm)] /// #[derive(FromForm)]
@ -118,6 +121,7 @@ use outcome::Outcome::*;
/// ///
/// ```rust /// ```rust
/// # #![feature(plugin, custom_derive)] /// # #![feature(plugin, custom_derive)]
/// # #![allow(deprecated, unused_attributes)]
/// # #![plugin(rocket_codegen)] /// # #![plugin(rocket_codegen)]
/// # extern crate rocket; /// # extern crate rocket;
/// # use rocket::request::Form; /// # use rocket::request::Form;

View File

@ -169,6 +169,7 @@ impl<S, E> IntoOutcome<S, (Status, E), ()> for Result<S, E> {
/// ///
/// #[get("/sensitive")] /// #[get("/sensitive")]
/// fn sensitive(key: APIKey) -> &'static str { /// fn sensitive(key: APIKey) -> &'static str {
/// # let _key = key;
/// "Sensitive data." /// "Sensitive data."
/// } /// }
/// ///

View File

@ -24,6 +24,7 @@ use http::uri::{URI, Segments, SegmentError};
/// # extern crate rocket; /// # extern crate rocket;
/// #[get("/<id>")] /// #[get("/<id>")]
/// fn hello(id: usize) -> String { /// fn hello(id: usize) -> String {
/// # let _id = id;
/// # /* /// # /*
/// ... /// ...
/// # */ /// # */
@ -127,6 +128,7 @@ use http::uri::{URI, Segments, SegmentError};
/// `key` and the number after the colon is stored in `value`: /// `key` and the number after the colon is stored in `value`:
/// ///
/// ```rust /// ```rust
/// # #[allow(dead_code)]
/// struct MyParam<'r> { /// struct MyParam<'r> {
/// key: &'r str, /// key: &'r str,
/// value: usize /// value: usize
@ -137,6 +139,7 @@ use http::uri::{URI, Segments, SegmentError};
/// ///
/// ```rust /// ```rust
/// use rocket::request::FromParam; /// use rocket::request::FromParam;
/// # #[allow(dead_code)]
/// # struct MyParam<'r> { key: &'r str, value: usize } /// # struct MyParam<'r> { key: &'r str, value: usize }
/// ///
/// impl<'r> FromParam<'r> for MyParam<'r> { /// impl<'r> FromParam<'r> for MyParam<'r> {
@ -170,6 +173,7 @@ use http::uri::{URI, Segments, SegmentError};
/// # #![plugin(rocket_codegen)] /// # #![plugin(rocket_codegen)]
/// # extern crate rocket; /// # extern crate rocket;
/// # use rocket::request::FromParam; /// # use rocket::request::FromParam;
/// # #[allow(dead_code)]
/// # struct MyParam<'r> { key: &'r str, value: usize } /// # struct MyParam<'r> { key: &'r str, value: usize }
/// # impl<'r> FromParam<'r> for MyParam<'r> { /// # impl<'r> FromParam<'r> for MyParam<'r> {
/// # type Error = &'r str; /// # type Error = &'r str;
@ -180,6 +184,7 @@ use http::uri::{URI, Segments, SegmentError};
/// # /// #
/// #[get("/<key_val>")] /// #[get("/<key_val>")]
/// fn hello(key_val: MyParam) -> String { /// fn hello(key_val: MyParam) -> String {
/// # let _kv = key_val;
/// # /* /// # /*
/// ... /// ...
/// # */ /// # */

View File

@ -44,6 +44,7 @@ impl<'r> Request<'r> {
/// use rocket::Request; /// use rocket::Request;
/// use rocket::http::Method; /// use rocket::http::Method;
/// ///
/// # #[allow(unused_variables)]
/// let request = Request::new(Method::Get, "/uri"); /// let request = Request::new(Method::Get, "/uri");
/// ``` /// ```
pub fn new<U: Into<URI<'r>>>(method: Method, uri: U) -> Request<'r> { pub fn new<U: Into<URI<'r>>>(method: Method, uri: U) -> Request<'r> {
@ -101,7 +102,7 @@ impl<'r> Request<'r> {
/// use rocket::Request; /// use rocket::Request;
/// use rocket::http::Method; /// use rocket::http::Method;
/// ///
/// let mut request = Request::new(Method::Get, "/uri"); /// let request = Request::new(Method::Get, "/uri");
/// assert_eq!(request.uri().as_str(), "/uri"); /// assert_eq!(request.uri().as_str(), "/uri");
/// ``` /// ```
#[inline(always)] #[inline(always)]
@ -179,9 +180,9 @@ impl<'r> Request<'r> {
/// ///
/// ```rust /// ```rust
/// use rocket::Request; /// use rocket::Request;
/// use rocket::http::{Method, ContentType}; /// use rocket::http::Method;
/// ///
/// let mut request = Request::new(Method::Get, "/uri"); /// let request = Request::new(Method::Get, "/uri");
/// let header_map = request.headers(); /// let header_map = request.headers();
/// assert!(header_map.is_empty()); /// assert!(header_map.is_empty());
/// ``` /// ```
@ -244,9 +245,9 @@ impl<'r> Request<'r> {
/// ///
/// ```rust /// ```rust
/// use rocket::Request; /// use rocket::Request;
/// use rocket::http::{Cookie, Method, ContentType}; /// use rocket::http::{Cookie, Method};
/// ///
/// let mut request = Request::new(Method::Get, "/uri"); /// let request = Request::new(Method::Get, "/uri");
/// request.cookies().add(Cookie::new("key", "val")); /// request.cookies().add(Cookie::new("key", "val"));
/// request.cookies().add(Cookie::new("ans", format!("life: {}", 38 + 4))); /// request.cookies().add(Cookie::new("ans", format!("life: {}", 38 + 4)));
/// ``` /// ```
@ -300,6 +301,7 @@ impl<'r> Request<'r> {
/// use rocket::{Request, Data}; /// use rocket::{Request, Data};
/// use rocket::handler::Outcome; /// use rocket::handler::Outcome;
/// ///
/// # #[allow(dead_code)]
/// fn name<'a>(req: &'a Request, _: Data) -> Outcome<'a> { /// fn name<'a>(req: &'a Request, _: Data) -> Outcome<'a> {
/// Outcome::of(req.get_param(0).unwrap_or("unnamed")) /// Outcome::of(req.get_param(0).unwrap_or("unnamed"))
/// } /// }

View File

@ -18,6 +18,7 @@
//! ```rust //! ```rust
//! use rocket::response::content; //! use rocket::response::content;
//! //!
//! # #[allow(unused_variables)]
//! let response = content::HTML("<h1>Hello, world!</h1>"); //! let response = content::HTML("<h1>Hello, world!</h1>");
//! ``` //! ```
@ -36,6 +37,7 @@ use http::{Status, ContentType};
/// use rocket::response::content::Content; /// use rocket::response::content::Content;
/// use rocket::http::ContentType; /// use rocket::http::ContentType;
/// ///
/// # #[allow(unused_variables)]
/// let response = Content(ContentType::PDF, "Hi."); /// let response = Content(ContentType::PDF, "Hi.");
/// ``` /// ```
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]

View File

@ -101,6 +101,7 @@ impl<'r, R: Responder<'r>> Flash<R> {
/// ```rust /// ```rust
/// use rocket::response::{Redirect, Flash}; /// use rocket::response::{Redirect, Flash};
/// ///
/// # #[allow(unused_variables)]
/// let msg = Flash::new(Redirect::to("/"), "suggestion", "Try this out!"); /// let msg = Flash::new(Redirect::to("/"), "suggestion", "Try this out!");
/// ``` /// ```
pub fn new<N: AsRef<str>, M: AsRef<str>>(res: R, name: N, msg: M) -> Flash<R> { pub fn new<N: AsRef<str>, M: AsRef<str>>(res: R, name: N, msg: M) -> Flash<R> {
@ -122,6 +123,7 @@ impl<'r, R: Responder<'r>> Flash<R> {
/// ```rust /// ```rust
/// use rocket::response::{Redirect, Flash}; /// use rocket::response::{Redirect, Flash};
/// ///
/// # #[allow(unused_variables)]
/// let msg = Flash::success(Redirect::to("/"), "It worked!"); /// let msg = Flash::success(Redirect::to("/"), "It worked!");
/// ``` /// ```
pub fn success<S: AsRef<str>>(responder: R, msg: S) -> Flash<R> { pub fn success<S: AsRef<str>>(responder: R, msg: S) -> Flash<R> {
@ -139,6 +141,7 @@ impl<'r, R: Responder<'r>> Flash<R> {
/// ```rust /// ```rust
/// use rocket::response::{Redirect, Flash}; /// use rocket::response::{Redirect, Flash};
/// ///
/// # #[allow(unused_variables)]
/// let msg = Flash::warning(Redirect::to("/"), "Watch out!"); /// let msg = Flash::warning(Redirect::to("/"), "Watch out!");
/// ``` /// ```
pub fn warning<S: AsRef<str>>(responder: R, msg: S) -> Flash<R> { pub fn warning<S: AsRef<str>>(responder: R, msg: S) -> Flash<R> {
@ -156,6 +159,7 @@ impl<'r, R: Responder<'r>> Flash<R> {
/// ```rust /// ```rust
/// use rocket::response::{Redirect, Flash}; /// use rocket::response::{Redirect, Flash};
/// ///
/// # #[allow(unused_variables)]
/// let msg = Flash::error(Redirect::to("/"), "Whoops!"); /// let msg = Flash::error(Redirect::to("/"), "Whoops!");
/// ``` /// ```
pub fn error<S: AsRef<str>>(responder: R, msg: S) -> Flash<R> { pub fn error<S: AsRef<str>>(responder: R, msg: S) -> Flash<R> {

View File

@ -25,6 +25,7 @@ impl NamedFile {
/// ```rust /// ```rust
/// use rocket::response::NamedFile; /// use rocket::response::NamedFile;
/// ///
/// # #[allow(unused_variables)]
/// let file = NamedFile::open("foo.txt"); /// let file = NamedFile::open("foo.txt");
/// ``` /// ```
pub fn open<P: AsRef<Path>>(path: P) -> io::Result<NamedFile> { pub fn open<P: AsRef<Path>>(path: P) -> io::Result<NamedFile> {
@ -58,6 +59,7 @@ impl NamedFile {
/// # use std::io; /// # use std::io;
/// use rocket::response::NamedFile; /// use rocket::response::NamedFile;
/// ///
/// # #[allow(dead_code)]
/// # fn demo_path() -> io::Result<()> { /// # fn demo_path() -> io::Result<()> {
/// let file = NamedFile::open("foo.txt")?; /// let file = NamedFile::open("foo.txt")?;
/// assert_eq!(file.path().as_os_str(), "foo.txt"); /// assert_eq!(file.path().as_os_str(), "foo.txt");

View File

@ -19,6 +19,7 @@ impl Redirect {
/// ```rust /// ```rust
/// use rocket::response::Redirect; /// use rocket::response::Redirect;
/// ///
/// # #[allow(unused_variables)]
/// let redirect = Redirect::to("/other_url"); /// let redirect = Redirect::to("/other_url");
/// ``` /// ```
pub fn to(uri: &str) -> Redirect { pub fn to(uri: &str) -> Redirect {
@ -36,6 +37,7 @@ impl Redirect {
/// ```rust /// ```rust
/// use rocket::response::Redirect; /// use rocket::response::Redirect;
/// ///
/// # #[allow(unused_variables)]
/// let redirect = Redirect::temporary("/other_url"); /// let redirect = Redirect::temporary("/other_url");
/// ``` /// ```
pub fn temporary(uri: &str) -> Redirect { pub fn temporary(uri: &str) -> Redirect {
@ -54,6 +56,7 @@ impl Redirect {
/// ```rust /// ```rust
/// use rocket::response::Redirect; /// use rocket::response::Redirect;
/// ///
/// # #[allow(unused_variables)]
/// let redirect = Redirect::permanent("/other_url"); /// let redirect = Redirect::permanent("/other_url");
/// ``` /// ```
pub fn permanent(uri: &str) -> Redirect { pub fn permanent(uri: &str) -> Redirect {
@ -72,6 +75,7 @@ impl Redirect {
/// ```rust /// ```rust
/// use rocket::response::Redirect; /// use rocket::response::Redirect;
/// ///
/// # #[allow(unused_variables)]
/// let redirect = Redirect::found("/other_url"); /// let redirect = Redirect::found("/other_url");
/// ``` /// ```
pub fn found(uri: &str) -> Redirect { pub fn found(uri: &str) -> Redirect {
@ -88,6 +92,7 @@ impl Redirect {
/// ```rust /// ```rust
/// use rocket::response::Redirect; /// use rocket::response::Redirect;
/// ///
/// # #[allow(unused_variables)]
/// let redirect = Redirect::moved("/other_url"); /// let redirect = Redirect::moved("/other_url");
/// ``` /// ```
pub fn moved(uri: &str) -> Redirect { pub fn moved(uri: &str) -> Redirect {

View File

@ -100,6 +100,8 @@ use response::{Response, Stream};
/// Say that you have a custom type, `Person`: /// Say that you have a custom type, `Person`:
/// ///
/// ```rust /// ```rust
///
/// # #[allow(dead_code)]
/// struct Person { /// struct Person {
/// name: String, /// name: String,
/// age: u16 /// age: u16

View File

@ -129,6 +129,7 @@ impl<T> fmt::Debug for Body<T> {
/// use rocket::response::Response; /// use rocket::response::Response;
/// use rocket::http::{Status, ContentType}; /// use rocket::http::{Status, ContentType};
/// ///
/// # #[allow(unused_variables)]
/// let response = Response::build() /// let response = Response::build()
/// .status(Status::ImATeapot) /// .status(Status::ImATeapot)
/// .header(ContentType::Plain) /// .header(ContentType::Plain)
@ -152,6 +153,7 @@ impl<'r> ResponseBuilder<'r> {
/// ```rust /// ```rust
/// use rocket::response::{ResponseBuilder, Response}; /// use rocket::response::{ResponseBuilder, Response};
/// ///
/// # #[allow(unused_variables)]
/// let builder = ResponseBuilder::new(Response::new()); /// let builder = ResponseBuilder::new(Response::new());
/// ``` /// ```
#[inline(always)] #[inline(always)]
@ -169,6 +171,7 @@ impl<'r> ResponseBuilder<'r> {
/// use rocket::Response; /// use rocket::Response;
/// use rocket::http::Status; /// use rocket::http::Status;
/// ///
/// # #[allow(unused_variables)]
/// let response = Response::build() /// let response = Response::build()
/// .status(Status::NotFound) /// .status(Status::NotFound)
/// .finalize(); /// .finalize();
@ -187,6 +190,7 @@ impl<'r> ResponseBuilder<'r> {
/// ```rust /// ```rust
/// use rocket::Response; /// use rocket::Response;
/// ///
/// # #[allow(unused_variables)]
/// let response = Response::build() /// let response = Response::build()
/// .raw_status(699, "Alien Encounter") /// .raw_status(699, "Alien Encounter")
/// .finalize(); /// .finalize();
@ -269,7 +273,6 @@ impl<'r> ResponseBuilder<'r> {
/// ///
/// ```rust /// ```rust
/// use rocket::Response; /// use rocket::Response;
/// use rocket::http::ContentType;
/// ///
/// let response = Response::build() /// let response = Response::build()
/// .raw_header("X-Custom", "first") /// .raw_header("X-Custom", "first")
@ -323,7 +326,9 @@ impl<'r> ResponseBuilder<'r> {
/// use std::fs::File; /// use std::fs::File;
/// # use std::io; /// # use std::io;
/// ///
/// # #[allow(dead_code)]
/// # fn test() -> io::Result<()> { /// # fn test() -> io::Result<()> {
/// # #[allow(unused_variables)]
/// let response = Response::build() /// let response = Response::build()
/// .sized_body(File::open("body.txt")?) /// .sized_body(File::open("body.txt")?)
/// .finalize(); /// .finalize();
@ -347,7 +352,9 @@ impl<'r> ResponseBuilder<'r> {
/// use std::fs::File; /// use std::fs::File;
/// # use std::io; /// # use std::io;
/// ///
/// # #[allow(dead_code)]
/// # fn test() -> io::Result<()> { /// # fn test() -> io::Result<()> {
/// # #[allow(unused_variables)]
/// let response = Response::build() /// let response = Response::build()
/// .streamed_body(File::open("body.txt")?) /// .streamed_body(File::open("body.txt")?)
/// .finalize(); /// .finalize();
@ -372,7 +379,9 @@ impl<'r> ResponseBuilder<'r> {
/// use std::fs::File; /// use std::fs::File;
/// # use std::io; /// # use std::io;
/// ///
/// # #[allow(dead_code)]
/// # fn test() -> io::Result<()> { /// # fn test() -> io::Result<()> {
/// # #[allow(unused_variables)]
/// let response = Response::build() /// let response = Response::build()
/// .chunked_body(File::open("body.txt")?, 8096) /// .chunked_body(File::open("body.txt")?, 8096)
/// .finalize(); /// .finalize();
@ -481,6 +490,7 @@ impl<'r> ResponseBuilder<'r> {
/// ```rust /// ```rust
/// use rocket::Response; /// use rocket::Response;
/// ///
/// # #[allow(unused_variables)]
/// let response = Response::build() /// let response = Response::build()
/// // build the response /// // build the response
/// .finalize(); /// .finalize();
@ -551,6 +561,7 @@ impl<'r> Response<'r> {
/// ```rust /// ```rust
/// use rocket::Response; /// use rocket::Response;
/// ///
/// # #[allow(unused_variables)]
/// let builder = Response::build(); /// let builder = Response::build();
/// ``` /// ```
#[inline(always)] #[inline(always)]
@ -563,6 +574,7 @@ impl<'r> Response<'r> {
/// # Example /// # Example
/// ///
/// ```rust /// ```rust
/// # #![allow(unused_variables)]
/// use rocket::Response; /// use rocket::Response;
/// ///
/// let other = Response::new(); /// let other = Response::new();
@ -791,7 +803,6 @@ impl<'r> Response<'r> {
/// ///
/// ```rust /// ```rust
/// use rocket::Response; /// use rocket::Response;
/// use rocket::http::Header;
/// ///
/// let mut response = Response::new(); /// let mut response = Response::new();
/// ///

View File

@ -26,6 +26,7 @@ use http::Status;
/// ///
/// let url = "http://myservice.com/resource.json".to_string(); /// let url = "http://myservice.com/resource.json".to_string();
/// let content = "{ 'resource': 'Hello, world!' }"; /// let content = "{ 'resource': 'Hello, world!' }";
/// # #[allow(unused_variables)]
/// let response = status::Created(url, Some(content)); /// let response = status::Created(url, Some(content));
/// ``` /// ```
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
@ -81,6 +82,7 @@ impl<'r, R: Responder<'r> + Hash> Responder<'r> for Created<R> {
/// ```rust /// ```rust
/// use rocket::response::status; /// use rocket::response::status;
/// ///
/// # #[allow(unused_variables)]
/// let response = status::Accepted::<()>(None); /// let response = status::Accepted::<()>(None);
/// ``` /// ```
/// ///
@ -89,6 +91,7 @@ impl<'r, R: Responder<'r> + Hash> Responder<'r> for Created<R> {
/// ```rust /// ```rust
/// use rocket::response::status; /// use rocket::response::status;
/// ///
/// # #[allow(unused_variables)]
/// let response = status::Accepted(Some("processing")); /// let response = status::Accepted(Some("processing"));
/// ``` /// ```
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
@ -114,6 +117,7 @@ impl<'r, R: Responder<'r>> Responder<'r> for Accepted<R> {
/// ```rust /// ```rust
/// use rocket::response::status; /// use rocket::response::status;
/// ///
/// # #[allow(unused_variables)]
/// let response = status::NoContent; /// let response = status::NoContent;
/// ``` /// ```
// TODO: This would benefit from Header support. // TODO: This would benefit from Header support.
@ -136,6 +140,7 @@ impl<'r> Responder<'r> for NoContent {
/// ```rust /// ```rust
/// use rocket::response::status; /// use rocket::response::status;
/// ///
/// # #[allow(unused_variables)]
/// let response = status::Reset; /// let response = status::Reset;
/// ``` /// ```
#[derive(Debug, Copy, Clone, PartialEq)] #[derive(Debug, Copy, Clone, PartialEq)]
@ -157,6 +162,7 @@ impl<'r> Responder<'r> for Reset {
/// use rocket::response::status; /// use rocket::response::status;
/// use rocket::http::Status; /// use rocket::http::Status;
/// ///
/// # #[allow(unused_variables)]
/// let response = status::Custom(Status::ImATeapot, "Hi!"); /// let response = status::Custom(Status::ImATeapot, "Hi!");
/// ``` /// ```
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]

View File

@ -24,6 +24,7 @@ impl<T: Read> Stream<T> {
/// use std::io; /// use std::io;
/// use rocket::response::Stream; /// use rocket::response::Stream;
/// ///
/// # #[allow(unused_variables)]
/// let response = Stream::from(io::stdin()); /// let response = Stream::from(io::stdin());
/// ``` /// ```
pub fn from(reader: T) -> Stream<T> { pub fn from(reader: T) -> Stream<T> {
@ -42,6 +43,7 @@ impl<T: Read> Stream<T> {
/// use std::io; /// use std::io;
/// use rocket::response::Stream; /// use rocket::response::Stream;
/// ///
/// # #[allow(unused_variables)]
/// let response = Stream::chunked(io::stdin(), 10); /// let response = Stream::chunked(io::stdin(), 10);
/// ``` /// ```
pub fn chunked(reader: T, chunk_size: u64) -> Stream<T> { pub fn chunked(reader: T, chunk_size: u64) -> Stream<T> {

View File

@ -317,12 +317,14 @@ impl Rocket {
/// use rocket::config::{Config, Environment}; /// use rocket::config::{Config, Environment};
/// # use rocket::config::ConfigError; /// # use rocket::config::ConfigError;
/// ///
/// # #[allow(dead_code)]
/// # fn try_config() -> Result<(), ConfigError> { /// # fn try_config() -> Result<(), ConfigError> {
/// let config = Config::build(Environment::Staging) /// let config = Config::build(Environment::Staging)
/// .address("1.2.3.4") /// .address("1.2.3.4")
/// .port(9234) /// .port(9234)
/// .finalize()?; /// .finalize()?;
/// ///
/// # #[allow(unused_variables)]
/// let app = rocket::custom(config, false); /// let app = rocket::custom(config, false);
/// # Ok(()) /// # Ok(())
/// # } /// # }
@ -509,6 +511,7 @@ impl Rocket {
/// fn main() { /// fn main() {
/// # if false { // We don't actually want to launch the server in an example. /// # if false { // We don't actually want to launch the server in an example.
/// rocket::ignite() /// rocket::ignite()
/// .mount("/", routes![index])
/// .manage(MyValue(10)) /// .manage(MyValue(10))
/// # .launch() /// # .launch()
/// # } /// # }

View File

@ -137,6 +137,7 @@ impl<'r> MockRequest<'r> {
/// use rocket::testing::MockRequest; /// use rocket::testing::MockRequest;
/// use rocket::http::ContentType; /// use rocket::http::ContentType;
/// ///
/// # #[allow(unused_variables)]
/// let req = MockRequest::new(Get, "/").header(ContentType::JSON); /// let req = MockRequest::new(Get, "/").header(ContentType::JSON);
/// ``` /// ```
#[inline] #[inline]
@ -175,6 +176,7 @@ impl<'r> MockRequest<'r> {
/// use rocket::testing::MockRequest; /// use rocket::testing::MockRequest;
/// ///
/// let address = "8.8.8.8:80".parse().unwrap(); /// let address = "8.8.8.8:80".parse().unwrap();
/// # #[allow(unused_variables)]
/// let req = MockRequest::new(Get, "/").remote(address); /// let req = MockRequest::new(Get, "/").remote(address);
/// ``` /// ```
#[inline] #[inline]
@ -194,6 +196,7 @@ impl<'r> MockRequest<'r> {
/// use rocket::testing::MockRequest; /// use rocket::testing::MockRequest;
/// use rocket::http::Cookie; /// use rocket::http::Cookie;
/// ///
/// # #[allow(unused_variables)]
/// let req = MockRequest::new(Get, "/") /// let req = MockRequest::new(Get, "/")
/// .cookie(Cookie::new("username", "sb")) /// .cookie(Cookie::new("username", "sb"))
/// .cookie(Cookie::new("user_id", format!("{}", 12))); /// .cookie(Cookie::new("user_id", format!("{}", 12)));
@ -215,6 +218,7 @@ impl<'r> MockRequest<'r> {
/// use rocket::testing::MockRequest; /// use rocket::testing::MockRequest;
/// use rocket::http::ContentType; /// use rocket::http::ContentType;
/// ///
/// # #[allow(unused_variables)]
/// let req = MockRequest::new(Post, "/") /// let req = MockRequest::new(Post, "/")
/// .header(ContentType::JSON) /// .header(ContentType::JSON)
/// .body(r#"{ "key": "value", "array": [1, 2, 3], }"#); /// .body(r#"{ "key": "value", "array": [1, 2, 3], }"#);