Created
January 16, 2017 05:45
-
-
Save jimmycuadra/e6b0590c88a70734d26fbe0032551032 to your computer and use it in GitHub Desktop.
Rough idea for a revision of ruma-api (using generic parameters instead of associated types)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub trait Endpoint<RQ, RS, S> where RQ: BuildRequest, RS: BuildResponse<S> { | |
fn build_request() -> RQ; | |
fn build_response() -> RS; | |
fn info() -> Info; | |
} | |
pub struct Info { | |
pub description: &'static str, | |
pub name: &'static str, | |
pub rate_limited: bool, | |
pub request_method: Method, | |
pub requires_authentication: bool, | |
pub router_path: &'static str, | |
} | |
pub trait BuildRequest { | |
fn body<T>(&self) -> Option<T> where T: Deserialize + Serialize; | |
fn headers(&self) -> Option<HashMap<&'static str, String>>; | |
fn path<T>(&self) -> Option<T> where T: Deserialize + Serialize; | |
fn query<T>(&self) -> Option<T> where T: Deserialize + Serialize; | |
} | |
pub trait BuildResponse<S> { | |
fn body<T>(&self) -> T where T: Deserialize + Serialize; | |
fn headers(&self) -> Option<HashMap<String, String>>; | |
fn status(&self) -> S; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment