Tweak http module docs.

This commit is contained in:
Sergio Benitez 2017-02-03 01:27:41 -08:00
parent a8356de183
commit bf1b9e76fd
2 changed files with 35 additions and 19 deletions

View File

@ -4,24 +4,23 @@
//! These types will, with certainty, be removed with time, but they reside here
//! while necessary.
#[doc(hidden)] pub use hyper::server::Request as Request;
#[doc(hidden)] pub use hyper::server::Response as Response;
#[doc(hidden)] pub use hyper::server::Server as Server;
#[doc(hidden)] pub use hyper::server::Handler as Handler;
pub(crate) use hyper::server::Request as Request;
pub(crate) use hyper::server::Response as Response;
pub(crate) use hyper::server::Server as Server;
pub(crate) use hyper::server::Handler as Handler;
pub(crate) use hyper::net;
#[doc(hidden)] pub use hyper::net;
#[doc(hidden)] pub use hyper::method::Method;
#[doc(hidden)] pub use hyper::status::StatusCode;
#[doc(hidden)] pub use hyper::uri::RequestUri;
#[doc(hidden)] pub use hyper::http::h1;
#[doc(hidden)] pub use hyper::buffer;
pub(crate) use hyper::method::Method;
pub(crate) use hyper::status::StatusCode;
pub(crate) use hyper::uri::RequestUri;
pub(crate) use hyper::http::h1;
pub(crate) use hyper::buffer;
pub use hyper::mime;
/// Type alias to `hyper::Response<'a, hyper::net::Fresh>`.
#[doc(hidden)] pub type FreshResponse<'a> = self::Response<'a, self::net::Fresh>;
pub(crate) type FreshResponse<'a> = self::Response<'a, self::net::Fresh>;
/// Reexported Hyper header types.
pub mod header {

View File

@ -25,8 +25,7 @@ pub enum Method {
}
impl Method {
#[doc(hidden)]
pub fn from_hyp(method: &hyper::Method) -> Option<Method> {
pub(crate) fn from_hyp(method: &hyper::Method) -> Option<Method> {
match *method {
hyper::Method::Get => Some(Get),
hyper::Method::Put => Some(Put),
@ -41,13 +40,22 @@ impl Method {
}
}
#[doc(hidden)]
#[inline(always)]
pub fn to_hyp(&self) -> hyper::Method {
#[inline]
pub(crate) fn to_hyp(&self) -> hyper::Method {
self.to_string().as_str().parse().unwrap()
}
/// Whether an HTTP request with the given method supports a payload.
/// Returns `true` ff an HTTP request with the method represented by `self`
/// supports a payload.
///
/// # Example
///
/// ```rust
/// use rocket::http::Method;
///
/// assert_eq!(Method::Get.supports_payload(), false);
/// assert_eq!(Method::Post.supports_payload(), true);
/// ```
pub fn supports_payload(&self) -> bool {
match *self {
Put | Post | Delete | Patch => true,
@ -55,7 +63,16 @@ impl Method {
}
}
#[inline(always)]
/// Returns the string representation of `self`.
///
/// # Example
///
/// ```rust
/// use rocket::http::Method;
///
/// assert_eq!(Method::Get.as_str(), "GET");
/// ```
#[inline]
pub fn as_str(&self) -> &'static str {
match *self {
Get => "GET",