use proc_macro2::Span;
use super::types::*;
macro_rules! impl_from_for_ty {
($($struct:ident => $variant:ident),* $(,)?) => {
$(
impl From<$struct> for TyKind {
fn from(value: $struct) -> Self {
TyKind::$variant(value)
}
}
impl From<$struct> for Ty {
fn from(value: $struct) -> Self {
Ty::new(Span::call_site(), TyKind::$variant(value))
}
}
#[allow(clippy::wrong_self_convention, dead_code)]
impl $struct {
pub(crate) fn to_ty(self) -> Ty {
self.into()
}
}
impl From<$struct> for Box<Ty> {
fn from(value: $struct) -> Self {
Box::new(value.into())
}
}
)*
};
}
impl_from_for_ty! {
TyArray => Array,
TyTuple => Tuple,
TyGroup => Group,
TyPrimitiveArray => PrimitiveArray,
TyPrimitive => Primitive,
TyGeneric => Generic,
TyTrait => Trait,
TyTypeParam => TypeParam,
TyFn => Fn,
TyWithPrefix => WithPrefix,
TyWithAttr => WithAttr,
TyWithTrait => WithTrait,
TyWithType => WithType,
TyWithCode => WithCode,
TyWithWhere => WithWhere,
TyNum => Num,
TyRange => Range,
TyError => Error,
}
impl From<Ty> for Option<Box<Ty>> {
fn from(ty: Ty) -> Self {
Some(ty.into())
}
}