Enum(Enum),
Def(DefId),
}
-//FIXME: change to from
-impl From<Module> for ModuleDef {
- fn from(it: Module) -> ModuleDef {
- ModuleDef::Module(it)
- }
-}
-
-impl From<Function> for ModuleDef {
- fn from(it: Function) -> ModuleDef {
- ModuleDef::Function(it)
- }
-}
-
-impl From<Struct> for ModuleDef {
- fn from(it: Struct) -> ModuleDef {
- ModuleDef::Struct(it)
- }
-}
-
-impl From<Enum> for ModuleDef {
- fn from(it: Enum) -> ModuleDef {
- ModuleDef::Enum(it)
- }
-}
+impl_froms!(ModuleDef: Module, Function, Struct, Enum);
impl From<DefId> for ModuleDef {
fn from(it: DefId) -> ModuleDef {
Enum(Enum),
Def(DefId),
}
-
-impl From<Function> for GenericDef {
- fn from(func: Function) -> GenericDef {
- GenericDef::Function(func)
- }
-}
-
-impl From<Struct> for GenericDef {
- fn from(s: Struct) -> GenericDef {
- GenericDef::Struct(s)
- }
-}
-
-impl From<Enum> for GenericDef {
- fn from(e: Enum) -> GenericDef {
- GenericDef::Enum(e)
- }
-}
+impl_froms!(GenericDef: Function, Struct, Enum);
impl From<DefId> for GenericDef {
fn from(def_id: DefId) -> GenericDef {
//! to a particular crate instance. That is, it has cfg flags and features
//! applied. So, the relation between syntax and HIR is many-to-one.
+macro_rules! impl_froms {
+ ($e:ident: $($v:ident), *) => {
+ $(
+ impl From<$v> for $e {
+ fn from(it: $v) -> $e {
+ $e::$v(it)
+ }
+ }
+ )*
+ }
+}
+
pub mod db;
#[cfg(test)]
mod mock;
Struct(Struct),
Enum(Enum),
}
-
-impl From<Struct> for AdtDef {
- fn from(s: Struct) -> AdtDef {
- AdtDef::Struct(s)
- }
-}
-
-impl From<Enum> for AdtDef {
- fn from(e: Enum) -> AdtDef {
- AdtDef::Enum(e)
- }
-}
+impl_froms!(AdtDef: Struct, Enum);
impl AdtDef {
fn krate(self, db: &impl HirDatabase) -> Option<Crate> {
Enum(Enum),
Def(DefId),
}
-
-impl From<Function> for TypableDef {
- fn from(func: Function) -> TypableDef {
- TypableDef::Function(func)
- }
-}
-
-impl From<Struct> for TypableDef {
- fn from(s: Struct) -> TypableDef {
- TypableDef::Struct(s)
- }
-}
-
-impl From<Enum> for TypableDef {
- fn from(e: Enum) -> TypableDef {
- TypableDef::Enum(e)
- }
-}
+impl_froms!(TypableDef: Function, Struct, Enum);
impl From<DefId> for TypableDef {
fn from(func: DefId) -> TypableDef {
Struct(Struct),
Def(DefId), // EnumVariant
}
-
-impl From<Struct> for VariantDef {
- fn from(struct_: Struct) -> VariantDef {
- VariantDef::Struct(struct_)
- }
-}
+impl_froms!(VariantDef: Struct);
impl From<DefId> for VariantDef {
fn from(def_id: DefId) -> VariantDef {