Skip to content

Instantly share code, notes, and snippets.

@jimmycuadra
Created January 16, 2017 05:45
Show Gist options
  • Save jimmycuadra/e6b0590c88a70734d26fbe0032551032 to your computer and use it in GitHub Desktop.
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)
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