Skip to content

Commit

Permalink
Response, Result: add From-Into for each
Browse files Browse the repository at this point in the history
Related to http-rs#452
  • Loading branch information
Fishrock123 committed May 26, 2020
1 parent f884167 commit c674dae
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,9 @@ where

/// A specialized Result type for Tide.
pub type Result<T = Response> = std::result::Result<T, Error>;

impl From<Response> for Result<Response> {
fn from(res: Response) -> Self {
Ok(res)
}
}
10 changes: 10 additions & 0 deletions src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,16 @@ impl<'a> From<&'a str> for Response {
}
}

impl<T, E> From<Result<T, E>> for Response
where T: Into<Response>, E: Into<Response> {
fn from(result: Result<T, E>) -> Self {
match result {
Ok(ok) => ok.into(),
Err(err) => err.into(),
}
}
}

impl IntoIterator for Response {
type Item = (HeaderName, HeaderValues);
type IntoIter = http_types::headers::IntoIter;
Expand Down

0 comments on commit c674dae

Please sign in to comment.