sway_core/language/parsed/expression/
method_name.rsuse crate::engine_threading::{EqWithEngines, PartialEqWithEngines, PartialEqWithEnginesContext};
use crate::language::CallPath;
use crate::type_system::TypeBinding;
use crate::{Ident, TypeArgument, TypeId, TypeInfo};
#[allow(clippy::large_enum_variant)]
#[derive(Debug, Clone)]
pub enum MethodName {
FromType {
call_path_binding: TypeBinding<CallPath<(TypeInfo, Ident)>>,
method_name: Ident,
},
FromModule { method_name: Ident },
FromTrait { call_path: CallPath },
FromQualifiedPathRoot {
ty: TypeArgument,
as_trait: TypeId,
method_name: Ident,
},
}
impl EqWithEngines for MethodName {}
impl PartialEqWithEngines for MethodName {
fn eq(&self, other: &Self, ctx: &PartialEqWithEnginesContext) -> bool {
match (self, other) {
(
MethodName::FromType {
call_path_binding,
method_name,
},
MethodName::FromType {
call_path_binding: r_call_path_binding,
method_name: r_method_name,
},
) => call_path_binding.eq(r_call_path_binding, ctx) && method_name == r_method_name,
(
MethodName::FromModule { method_name },
MethodName::FromModule {
method_name: r_method_name,
},
) => method_name == r_method_name,
(
MethodName::FromTrait { call_path },
MethodName::FromTrait {
call_path: r_call_path,
},
) => call_path == r_call_path,
(
MethodName::FromQualifiedPathRoot {
ty,
as_trait,
method_name,
},
MethodName::FromQualifiedPathRoot {
ty: r_ty,
as_trait: r_as_trait,
method_name: r_method_name,
},
) => ty.eq(r_ty, ctx) && as_trait.eq(r_as_trait) && method_name == r_method_name,
_ => false,
}
}
}
impl MethodName {
pub fn easy_name(&self) -> Ident {
match self {
MethodName::FromType { method_name, .. } => method_name.clone(),
MethodName::FromTrait { call_path, .. } => call_path.suffix.clone(),
MethodName::FromModule { method_name, .. } => method_name.clone(),
MethodName::FromQualifiedPathRoot { method_name, .. } => method_name.clone(),
}
}
}