Remove generic variable type from QueryUnwrap trait

This commit is contained in:
Kiana Sheibani 2023-09-02 21:22:29 -04:00
parent 9d5ff8f125
commit 98f140afff
Signed by: toki
GPG key ID: 6CB106C25E86A9F7
4 changed files with 2 additions and 22 deletions

View file

@ -59,18 +59,13 @@ pub struct Timestamp(pub u64);
// Query machinery // Query machinery
pub trait QueryUnwrap<Vars>: 'static + QueryBuilder<Vars> { pub trait QueryUnwrap<Vars>: 'static + QueryBuilder<Vars> {
type VarsUnwrapped;
type Unwrapped; type Unwrapped;
fn wrap_vars(vars: Self::VarsUnwrapped) -> Vars;
fn unwrap_response(response: GraphQlResponse<Self>) -> Option<Self::Unwrapped>; fn unwrap_response(response: GraphQlResponse<Self>) -> Option<Self::Unwrapped>;
} }
// Generic function for running start.gg queries // Generic function for running start.gg queries
pub fn run_query<Builder, Vars>( pub fn run_query<Builder, Vars>(vars: Vars, auth: &str) -> Option<Builder::Unwrapped>
vars: Builder::VarsUnwrapped,
auth: &str,
) -> Option<Builder::Unwrapped>
where where
Builder: QueryUnwrap<Vars>, Builder: QueryUnwrap<Vars>,
Vars: Serialize, Vars: Serialize,
@ -78,7 +73,7 @@ where
{ {
use cynic::http::ReqwestBlockingExt; use cynic::http::ReqwestBlockingExt;
let query = Builder::build(Builder::wrap_vars(vars)); let query = Builder::build(vars);
let response = reqwest::blocking::Client::new() let response = reqwest::blocking::Client::new()
.post("https://api.start.gg/gql/alpha") .post("https://api.start.gg/gql/alpha")

View file

@ -32,13 +32,8 @@ pub struct PlayerInfoResponse {
} }
impl QueryUnwrap<PlayerInfoVars> for PlayerInfo { impl QueryUnwrap<PlayerInfoVars> for PlayerInfo {
type VarsUnwrapped = PlayerInfoVars;
type Unwrapped = PlayerInfoResponse; type Unwrapped = PlayerInfoResponse;
fn wrap_vars(vars: PlayerInfoVars) -> PlayerInfoVars {
vars
}
fn unwrap_response(response: GraphQlResponse<PlayerInfo>) -> Option<PlayerInfoResponse> { fn unwrap_response(response: GraphQlResponse<PlayerInfo>) -> Option<PlayerInfoResponse> {
let player = response.data?.player?; let player = response.data?.player?;
Some(PlayerInfoResponse { Some(PlayerInfoResponse {

View file

@ -38,13 +38,8 @@ pub struct VideogameResponse {
} }
impl<'a> QueryUnwrap<VideogameSearchVars<'a>> for VideogameSearch { impl<'a> QueryUnwrap<VideogameSearchVars<'a>> for VideogameSearch {
type VarsUnwrapped = VideogameSearchVars<'a>;
type Unwrapped = Vec<VideogameResponse>; type Unwrapped = Vec<VideogameResponse>;
fn wrap_vars(vars: VideogameSearchVars) -> VideogameSearchVars {
vars
}
fn unwrap_response( fn unwrap_response(
response: GraphQlResponse<VideogameSearch>, response: GraphQlResponse<VideogameSearch>,
) -> Option<Vec<VideogameResponse>> { ) -> Option<Vec<VideogameResponse>> {

View file

@ -106,13 +106,8 @@ pub struct SetResponse {
} }
impl<'a> QueryUnwrap<TournamentSetsVars<'a>> for TournamentSets { impl<'a> QueryUnwrap<TournamentSetsVars<'a>> for TournamentSets {
type VarsUnwrapped = TournamentSetsVars<'a>;
type Unwrapped = Vec<TournamentResponse>; type Unwrapped = Vec<TournamentResponse>;
fn wrap_vars(vars: TournamentSetsVars) -> TournamentSetsVars {
vars
}
// This might be the most spaghetti code I've ever written // This might be the most spaghetti code I've ever written
fn unwrap_response( fn unwrap_response(
response: GraphQlResponse<TournamentSets>, response: GraphQlResponse<TournamentSets>,