add form() method
This commit is contained in:
14
src/error.rs
14
src/error.rs
@@ -6,6 +6,11 @@ use std::fmt;
|
||||
pub enum Error {
|
||||
/// An HTTP error from the `hyper` crate.
|
||||
Http(::hyper::Error),
|
||||
/// An error trying to serialize a value.
|
||||
///
|
||||
/// This may be serializing a value that is illegal in JSON or
|
||||
/// form-url-encoded bodies.
|
||||
Serialize(Box<StdError>),
|
||||
/// A request tried to redirect too many times.
|
||||
TooManyRedirects,
|
||||
#[doc(hidden)]
|
||||
@@ -16,6 +21,7 @@ impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
Error::Http(ref e) => fmt::Display::fmt(e, f),
|
||||
Error::Serialize(ref e) => fmt::Display::fmt(e, f),
|
||||
Error::TooManyRedirects => {
|
||||
f.pad("Too many redirects")
|
||||
},
|
||||
@@ -28,6 +34,7 @@ impl StdError for Error {
|
||||
fn description(&self) -> &str {
|
||||
match *self {
|
||||
Error::Http(ref e) => e.description(),
|
||||
Error::Serialize(ref e) => e.description(),
|
||||
Error::TooManyRedirects => "Too many redirects",
|
||||
Error::__DontMatchMe => unreachable!()
|
||||
}
|
||||
@@ -36,6 +43,7 @@ impl StdError for Error {
|
||||
fn cause(&self) -> Option<&StdError> {
|
||||
match *self {
|
||||
Error::Http(ref e) => Some(e),
|
||||
Error::Serialize(ref e) => Some(&**e),
|
||||
Error::TooManyRedirects => None,
|
||||
Error::__DontMatchMe => unreachable!()
|
||||
}
|
||||
@@ -54,7 +62,11 @@ impl From<::url::ParseError> for Error {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl From<::serde_urlencoded::ser::Error> for Error {
|
||||
fn from(err: ::serde_urlencoded::ser::Error) -> Error {
|
||||
Error::Serialize(Box::new(err))
|
||||
}
|
||||
}
|
||||
|
||||
/// A `Result` alias where the `Err` case is `reqwest::Error`.
|
||||
pub type Result<T> = ::std::result::Result<T, Error>;
|
||||
|
||||
Reference in New Issue
Block a user