use quick_error::quick_error; use std::io; quick_error! { #[derive(Debug)] pub enum Error { Detail(description: String) { display("{}", description) } PostBody(err: io::Error) { display("An IO error occurred while uploading the body of a POST request") from() source(err) } } } pub struct GetResponse { pub headers: H, pub body: B, } pub struct PostResponse { /// **Note**: Implementations should drop the handle to avoid deadlocks pub post_body: PB, pub headers: H, pub body: B, } impl From> for GetResponse { fn from(v: PostResponse) -> Self { GetResponse { headers: v.headers, body: v.body, } } } #[allow(clippy::type_complexity)] pub trait Http { type Headers: io::BufRead; type ResponseBody: io::BufRead; type PostBody: io::Write; fn get( &mut self, url: &str, headers: impl IntoIterator>, ) -> Result, Error>; fn post( &mut self, url: &str, headers: impl IntoIterator>, ) -> Result, Error>; }