HIR
Add casting method for Function variant of ModuleDefId
@@ -265,6 +265,23 @@ pub enum ModuleDefId {
FunctionId(FuncId),
}
+impl ModuleDefId {
+ pub fn as_function(&self) -> Option<FuncId> {
+ if let ModuleDefId::FunctionId(func_id) = self {
+ return Some(*func_id)
+ }
+ return None
+ }
+ // XXX: We are still allocating fro error reporting even though strings are stored in binary
+ // It is a minor performance issue, which can be addressed by having the error reporting, not allocate
+ pub fn as_str(&self) -> &'static str {
+ match self {
+ ModuleDefId::FunctionId(_) => "function",
+ ModuleDefId::ModuleId(_) => "module",
+ }
+ }
+}
+
impl Into<ModuleDefId> for ModuleId {
fn into(self) -> ModuleDefId {
ModuleDefId::ModuleId(self)
