use proc_macro2::TokenStream;
use super::{type_path::TypePath, Ident};
pub struct GenericParameter {
pub name: Ident,
pub constraint: GenericConstraint,
}
impl GenericParameter {
pub fn to_tokens(&self, path_to_markers: TypePath) -> TokenStream {
use quote::quote;
let name = &self.name;
let constraint = self.constraint.to_tokens(path_to_markers);
quote! {
#name: #constraint
}
}
}
pub enum GenericConstraint {
Enum(Ident),
InputObject(Ident),
Scalar(TypePath),
}
impl GenericConstraint {
fn to_tokens(&self, path_to_markers: TypePath) -> TokenStream {
use quote::quote;
match self {
GenericConstraint::Enum(ident) => {
let type_path = TypePath::concat(&[path_to_markers, ident.clone().into()]);
quote! { ::cynic::Enum<#type_path> }
}
GenericConstraint::InputObject(ident) => {
let type_path = TypePath::concat(&[path_to_markers, ident.clone().into()]);
quote! { ::cynic::InputObject<#type_path> }
}
GenericConstraint::Scalar(scalar_path) => {
let type_path = TypePath::concat(&[path_to_markers, scalar_path.clone()]);
quote! { ::cynic::Scalar<#type_path> }
}
}
}
}