Merge pull request #68 from alexcrichton/rename-builders

Rename `Builder` to `{Request,Response}Builder`
This commit is contained in:
Alex Crichton
2017-07-28 21:10:27 -05:00
committed by GitHub
3 changed files with 42 additions and 42 deletions
+2 -2
View File
@@ -23,8 +23,8 @@ pub use error::{Error, Result};
pub use extensions::Extensions;
pub use header::HeaderMap;
pub use method::Method;
pub use request::Request;
pub use response::Response;
pub use request::{Request, RequestBuilder};
pub use response::{Response, ResponseBuilder};
pub use status::StatusCode;
pub use uri::Uri;
pub use version::Version;
+21 -21
View File
@@ -189,7 +189,7 @@ pub struct Parts {
/// This type can be used to construct an instance or `Request`
/// through a builder-like pattern.
#[derive(Debug)]
pub struct Builder {
pub struct RequestBuilder {
head: Option<Parts>,
err: Option<Error>,
}
@@ -197,7 +197,7 @@ pub struct Builder {
impl Request<()> {
/// Creates a new builder-style object to manufacture a `Request`
///
/// This method returns an instance of `Builder` which can be used to
/// This method returns an instance of `RequestBuilder` which can be used to
/// create a `Request`.
///
/// # Examples
@@ -212,8 +212,8 @@ impl Request<()> {
/// .unwrap();
/// ```
#[inline]
pub fn builder() -> Builder {
Builder::new()
pub fn builder() -> RequestBuilder {
RequestBuilder::new()
}
}
@@ -486,8 +486,8 @@ impl Parts {
}
}
impl Builder {
/// Creates a new default instance of `Builder` to construct either a
impl RequestBuilder {
/// Creates a new default instance of `RequestBuilder` to construct either a
/// `Head` or a `Request`.
///
/// # Examples
@@ -495,20 +495,20 @@ impl Builder {
/// ```
/// # use http::*;
///
/// let req = request::Builder::new()
/// let req = request::RequestBuilder::new()
/// .method("POST")
/// .body(())
/// .unwrap();
/// ```
#[inline]
pub fn new() -> Builder {
Builder::default()
pub fn new() -> RequestBuilder {
RequestBuilder::default()
}
/// Set the HTTP method for this request.
///
/// This function will configure the HTTP method of the `Request` that will
/// be returned from `Builder::build`.
/// be returned from `RequestBuilder::build`.
///
/// By default this is `GET`.
///
@@ -522,7 +522,7 @@ impl Builder {
/// .body(())
/// .unwrap();
/// ```
pub fn method<T>(&mut self, method: T) -> &mut Builder
pub fn method<T>(&mut self, method: T) -> &mut RequestBuilder
where Method: HttpTryFrom<T>,
{
if let Some(head) = head(&mut self.head, &self.err) {
@@ -537,7 +537,7 @@ impl Builder {
/// Set the URI for this request.
///
/// This function will configure the URI of the `Request` that will
/// be returned from `Builder::build`.
/// be returned from `RequestBuilder::build`.
///
/// By default this is `/`.
///
@@ -551,7 +551,7 @@ impl Builder {
/// .body(())
/// .unwrap();
/// ```
pub fn uri<T>(&mut self, uri: T) -> &mut Builder
pub fn uri<T>(&mut self, uri: T) -> &mut RequestBuilder
where Uri: HttpTryFrom<T>,
{
if let Some(head) = head(&mut self.head, &self.err) {
@@ -566,7 +566,7 @@ impl Builder {
/// Set the HTTP version for this request.
///
/// This function will configure the HTTP version of the `Request` that
/// will be returned from `Builder::build`.
/// will be returned from `RequestBuilder::build`.
///
/// By default this is HTTP/1.1
///
@@ -581,7 +581,7 @@ impl Builder {
/// .body(())
/// .unwrap();
/// ```
pub fn version(&mut self, version: Version) -> &mut Builder {
pub fn version(&mut self, version: Version) -> &mut RequestBuilder {
if let Some(head) = head(&mut self.head, &self.err) {
head.version = version;
}
@@ -606,7 +606,7 @@ impl Builder {
/// .body(())
/// .unwrap();
/// ```
pub fn header<K, V>(&mut self, key: K, value: V) -> &mut Builder
pub fn header<K, V>(&mut self, key: K, value: V) -> &mut RequestBuilder
where K: HeaderMapKey,
HeaderValue: HttpTryFrom<V>
{
@@ -644,7 +644,7 @@ impl Builder {
/// .unwrap();
/// # fn needs_custom_bar_header() -> bool { true }
/// ```
pub fn headers<I, K, V>(&mut self, headers: I) -> &mut Builder
pub fn headers<I, K, V>(&mut self, headers: I) -> &mut RequestBuilder
where I: IntoIterator<Item = (K, V)>,
K: HeaderMapKey,
HeaderValue: HttpTryFrom<V>,
@@ -670,7 +670,7 @@ impl Builder {
/// assert_eq!(req.extensions().get::<&'static str>(),
/// Some(&"My Extension"));
/// ```
pub fn extension<T>(&mut self, extension: T) -> &mut Builder
pub fn extension<T>(&mut self, extension: T) -> &mut RequestBuilder
where T: Any + Send + Sync + 'static,
{
if let Some(head) = head(&mut self.head, &self.err) {
@@ -729,10 +729,10 @@ fn head<'a>(head: &'a mut Option<Parts>, err: &Option<Error>)
head.as_mut()
}
impl Default for Builder {
impl Default for RequestBuilder {
#[inline]
fn default() -> Builder {
Builder {
fn default() -> RequestBuilder {
RequestBuilder {
head: Some(Parts::new()),
err: None,
}
+19 -19
View File
@@ -213,7 +213,7 @@ pub struct Parts {
/// This type can be used to construct an instance of `Response` through a
/// builder-like pattern.
#[derive(Debug)]
pub struct Builder {
pub struct ResponseBuilder {
head: Option<Parts>,
err: Option<Error>,
}
@@ -221,7 +221,7 @@ pub struct Builder {
impl Response<()> {
/// Creates a new builder-style object to manufacture a `Response`
///
/// This method returns an instance of `Builder` which can be used to
/// This method returns an instance of `ResponseBuilder` which can be used to
/// create a `Response`.
///
/// # Examples
@@ -235,8 +235,8 @@ impl Response<()> {
/// .unwrap();
/// ```
#[inline]
pub fn builder() -> Builder {
Builder::new()
pub fn builder() -> ResponseBuilder {
ResponseBuilder::new()
}
}
@@ -481,8 +481,8 @@ impl Parts {
}
}
impl Builder {
/// Creates a new default instance of `Builder` to construct either a
impl ResponseBuilder {
/// Creates a new default instance of `ResponseBuilder` to construct either a
/// `Head` or a `Response`.
///
/// # Examples
@@ -490,20 +490,20 @@ impl Builder {
/// ```
/// # use http::*;
///
/// let response = response::Builder::new()
/// let response = response::ResponseBuilder::new()
/// .status(200)
/// .body(())
/// .unwrap();
/// ```
#[inline]
pub fn new() -> Builder {
Builder::default()
pub fn new() -> ResponseBuilder {
ResponseBuilder::default()
}
/// Set the HTTP method for this response.
///
/// This function will configure the HTTP status code of the `Response` that
/// will be returned from `Builder::build`.
/// will be returned from `ResponseBuilder::build`.
///
/// By default this is `GET`.
///
@@ -517,7 +517,7 @@ impl Builder {
/// .body(())
/// .unwrap();
/// ```
pub fn status<T>(&mut self, status: T) -> &mut Builder
pub fn status<T>(&mut self, status: T) -> &mut ResponseBuilder
where StatusCode: HttpTryFrom<T>,
{
if let Some(head) = head(&mut self.head, &self.err) {
@@ -532,7 +532,7 @@ impl Builder {
/// Set the HTTP version for this response.
///
/// This function will configure the HTTP version of the `Response` that
/// will be returned from `Builder::build`.
/// will be returned from `ResponseBuilder::build`.
///
/// By default this is HTTP/1.1
///
@@ -547,7 +547,7 @@ impl Builder {
/// .body(())
/// .unwrap();
/// ```
pub fn version(&mut self, version: Version) -> &mut Builder {
pub fn version(&mut self, version: Version) -> &mut ResponseBuilder {
if let Some(head) = head(&mut self.head, &self.err) {
head.version = version;
}
@@ -572,7 +572,7 @@ impl Builder {
/// .body(())
/// .unwrap();
/// ```
pub fn header<K, V>(&mut self, key: K, value: V) -> &mut Builder
pub fn header<K, V>(&mut self, key: K, value: V) -> &mut ResponseBuilder
where K: HeaderMapKey,
HeaderValue: HttpTryFrom<V>
{
@@ -610,7 +610,7 @@ impl Builder {
/// .unwrap();
/// # fn needs_custom_bar_header() -> bool { true }
/// ```
pub fn headers<I, K, V>(&mut self, headers: I) -> &mut Builder
pub fn headers<I, K, V>(&mut self, headers: I) -> &mut ResponseBuilder
where I: IntoIterator<Item = (K, V)>,
K: HeaderMapKey,
HeaderValue: HttpTryFrom<V>,
@@ -636,7 +636,7 @@ impl Builder {
/// assert_eq!(response.extensions().get::<&'static str>(),
/// Some(&"My Extension"));
/// ```
pub fn extension<T>(&mut self, extension: T) -> &mut Builder
pub fn extension<T>(&mut self, extension: T) -> &mut ResponseBuilder
where T: Any + Send + Sync + 'static,
{
if let Some(head) = head(&mut self.head, &self.err) {
@@ -695,10 +695,10 @@ fn head<'a>(head: &'a mut Option<Parts>, err: &Option<Error>)
head.as_mut()
}
impl Default for Builder {
impl Default for ResponseBuilder {
#[inline]
fn default() -> Builder {
Builder {
fn default() -> ResponseBuilder {
ResponseBuilder {
head: Some(Parts::new()),
err: None,
}