Remove generic variable type from QueryUnwrap trait
This commit is contained in:
parent
9d5ff8f125
commit
98f140afff
|
@ -59,18 +59,13 @@ pub struct Timestamp(pub u64);
|
|||
// Query machinery
|
||||
|
||||
pub trait QueryUnwrap<Vars>: 'static + QueryBuilder<Vars> {
|
||||
type VarsUnwrapped;
|
||||
type Unwrapped;
|
||||
|
||||
fn wrap_vars(vars: Self::VarsUnwrapped) -> Vars;
|
||||
fn unwrap_response(response: GraphQlResponse<Self>) -> Option<Self::Unwrapped>;
|
||||
}
|
||||
|
||||
// Generic function for running start.gg queries
|
||||
pub fn run_query<Builder, Vars>(
|
||||
vars: Builder::VarsUnwrapped,
|
||||
auth: &str,
|
||||
) -> Option<Builder::Unwrapped>
|
||||
pub fn run_query<Builder, Vars>(vars: Vars, auth: &str) -> Option<Builder::Unwrapped>
|
||||
where
|
||||
Builder: QueryUnwrap<Vars>,
|
||||
Vars: Serialize,
|
||||
|
@ -78,7 +73,7 @@ where
|
|||
{
|
||||
use cynic::http::ReqwestBlockingExt;
|
||||
|
||||
let query = Builder::build(Builder::wrap_vars(vars));
|
||||
let query = Builder::build(vars);
|
||||
|
||||
let response = reqwest::blocking::Client::new()
|
||||
.post("https://api.start.gg/gql/alpha")
|
||||
|
|
|
@ -32,13 +32,8 @@ pub struct PlayerInfoResponse {
|
|||
}
|
||||
|
||||
impl QueryUnwrap<PlayerInfoVars> for PlayerInfo {
|
||||
type VarsUnwrapped = PlayerInfoVars;
|
||||
type Unwrapped = PlayerInfoResponse;
|
||||
|
||||
fn wrap_vars(vars: PlayerInfoVars) -> PlayerInfoVars {
|
||||
vars
|
||||
}
|
||||
|
||||
fn unwrap_response(response: GraphQlResponse<PlayerInfo>) -> Option<PlayerInfoResponse> {
|
||||
let player = response.data?.player?;
|
||||
Some(PlayerInfoResponse {
|
||||
|
|
|
@ -38,13 +38,8 @@ pub struct VideogameResponse {
|
|||
}
|
||||
|
||||
impl<'a> QueryUnwrap<VideogameSearchVars<'a>> for VideogameSearch {
|
||||
type VarsUnwrapped = VideogameSearchVars<'a>;
|
||||
type Unwrapped = Vec<VideogameResponse>;
|
||||
|
||||
fn wrap_vars(vars: VideogameSearchVars) -> VideogameSearchVars {
|
||||
vars
|
||||
}
|
||||
|
||||
fn unwrap_response(
|
||||
response: GraphQlResponse<VideogameSearch>,
|
||||
) -> Option<Vec<VideogameResponse>> {
|
||||
|
|
|
@ -106,13 +106,8 @@ pub struct SetResponse {
|
|||
}
|
||||
|
||||
impl<'a> QueryUnwrap<TournamentSetsVars<'a>> for TournamentSets {
|
||||
type VarsUnwrapped = TournamentSetsVars<'a>;
|
||||
type Unwrapped = Vec<TournamentResponse>;
|
||||
|
||||
fn wrap_vars(vars: TournamentSetsVars) -> TournamentSetsVars {
|
||||
vars
|
||||
}
|
||||
|
||||
// This might be the most spaghetti code I've ever written
|
||||
fn unwrap_response(
|
||||
response: GraphQlResponse<TournamentSets>,
|
||||
|
|
Loading…
Reference in a new issue