core: Move Type impl block directly below type declaration

This commit is contained in:
David Mak 2024-06-25 15:44:18 +08:00
parent 91e3824517
commit c78accce70
1 changed files with 13 additions and 13 deletions

View File

@ -22,6 +22,19 @@ mod test;
/// Handle for a type, implemented as a key in the unification table. /// Handle for a type, implemented as a key in the unification table.
pub type Type = UnificationKey; pub type Type = UnificationKey;
impl Type {
/// Wrapper function for cleaner code so that we don't need to write this long pattern matching
/// just to get the field `obj_id`.
#[must_use]
pub fn obj_id(self, unifier: &Unifier) -> Option<DefinitionId> {
if let TypeEnum::TObj { obj_id, .. } = &*unifier.get_ty_immutable(self) {
Some(*obj_id)
} else {
None
}
}
}
#[derive(Clone, Copy, PartialEq, Eq, Debug)] #[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub struct CallId(pub(super) usize); pub struct CallId(pub(super) usize);
@ -109,19 +122,6 @@ pub enum RecordKey {
Int(i32), Int(i32),
} }
impl Type {
/// Wrapper function for cleaner code so that we don't need to write this long pattern matching
/// just to get the field `obj_id`.
#[must_use]
pub fn obj_id(self, unifier: &Unifier) -> Option<DefinitionId> {
if let TypeEnum::TObj { obj_id, .. } = &*unifier.get_ty_immutable(self) {
Some(*obj_id)
} else {
None
}
}
}
impl From<&RecordKey> for StrRef { impl From<&RecordKey> for StrRef {
fn from(r: &RecordKey) -> Self { fn from(r: &RecordKey) -> Self {
match r { match r {