Eliminate unnecessary ToMangled trait
diff --git a/syntax/mangled.rs b/syntax/mangled.rs
index a89060d..f52aa43 100644
--- a/syntax/mangled.rs
+++ b/syntax/mangled.rs
@@ -1,31 +1,25 @@
use crate::syntax::namespace::Namespace;
use crate::syntax::{Atom, Type};
-pub trait ToMangled {
- fn to_mangled(&self, namespace: &Namespace) -> String;
-}
-
-impl ToMangled for Type {
- fn to_mangled(&self, namespace: &Namespace) -> String {
- match self {
- Type::Ident(ident) => {
- let mut instance = String::new();
- // Do not apply namespace to built-in type
- let is_user_type = Atom::from(ident).is_none();
- if is_user_type {
- for name in namespace {
- instance += name;
- instance += "$";
- }
+pub fn to_mangled(namespace: &Namespace, ty: &Type) -> String {
+ match ty {
+ Type::Ident(ident) => {
+ let mut instance = String::new();
+ // Do not apply namespace to built-in type
+ let is_user_type = Atom::from(ident).is_none();
+ if is_user_type {
+ for name in namespace {
+ instance += name;
+ instance += "$";
}
- instance += &ident.to_string();
- instance
}
- Type::RustBox(ptr) => format!("rust_box${}", ptr.inner.to_mangled(namespace)),
- Type::RustVec(ptr) => format!("rust_vec${}", ptr.inner.to_mangled(namespace)),
- Type::UniquePtr(ptr) => format!("std$unique_ptr${}", ptr.inner.to_mangled(namespace)),
- Type::CxxVector(ptr) => format!("std$vector${}", ptr.inner.to_mangled(namespace)),
- _ => unimplemented!(),
+ instance += &ident.to_string();
+ instance
}
+ Type::RustBox(ptr) => format!("rust_box${}", to_mangled(namespace, &ptr.inner)),
+ Type::RustVec(ptr) => format!("rust_vec${}", to_mangled(namespace, &ptr.inner)),
+ Type::UniquePtr(ptr) => format!("std$unique_ptr${}", to_mangled(namespace, &ptr.inner)),
+ Type::CxxVector(ptr) => format!("std$vector${}", to_mangled(namespace, &ptr.inner)),
+ _ => unimplemented!(),
}
}