Panic on reuse of builders

This commit is contained in:
Alex Crichton
2017-07-26 13:00:42 -07:00
parent 24f89b259d
commit 280f2b4f65
2 changed files with 14 additions and 10 deletions
+7 -5
View File
@@ -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<Parts> {
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
///
/// ```
+7 -5
View File
@@ -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<Parts> {
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
///
/// ```