diff --git a/src/request.rs b/src/request.rs index b703990..f644028 100644 --- a/src/request.rs +++ b/src/request.rs @@ -1,7 +1,6 @@ //! HTTP request types. use std::any::Any; -use std::io; use {Uri, Error, Result, HttpTryFrom, Extensions}; use header::{HeaderMap, HeaderValue, HeaderMapKey}; @@ -511,13 +510,11 @@ impl Builder { /// "Consumes" this builder, returning the constructed `Head`. fn head(&mut self) -> Result { + let ret = self.head.take().expect("cannot reuse request builder"); if let Some(e) = self.err.take() { return Err(e) } - self.head.take().ok_or_else(|| { - io::Error::new(io::ErrorKind::Other, "cannot reuse `Builder`") - .into() - }) + Ok(ret) } /// "Consumes" this builder, using the provided `body` to return a @@ -531,6 +528,11 @@ impl Builder { /// "Bar\r\n")` the error will be returned when this function is called /// rather than when `header` was called. /// + /// # Panics + /// + /// This method will panic if the builder is reused. The `body` function can + /// only be called once. + /// /// # Examples /// /// ``` diff --git a/src/response.rs b/src/response.rs index 621b6df..27f6feb 100644 --- a/src/response.rs +++ b/src/response.rs @@ -1,7 +1,6 @@ //! HTTP response types. use std::any::Any; -use std::io; use {Error, Result, HttpTryFrom, Extensions}; use header::{HeaderMap, HeaderValue}; @@ -453,13 +452,11 @@ impl Builder { /// "Consumes" this builder, returning the constructed `Parts`. fn head(&mut self) -> Result { + let ret = self.head.take().expect("cannot reuse response builder"); if let Some(e) = self.err.take() { return Err(e) } - self.head.take().ok_or_else(|| { - io::Error::new(io::ErrorKind::Other, "cannot reuse `Builder`") - .into() - }) + Ok(ret) } /// "Consumes" this builder, using the provided `body` to return a @@ -473,6 +470,11 @@ impl Builder { /// "Bar\r\n")` the error will be returned when this function is called /// rather than when `header` was called. /// + /// # Panics + /// + /// This method will panic if the builder is reused. The `body` function can + /// only be called once. + /// /// # Examples /// /// ```