Skip to main content

mago_codex/identifier/
method.rs

1use serde::Deserialize;
2use serde::Serialize;
3
4use mago_atom::Atom;
5
6/// Represents a unique identifier for a method within a class-like structure.
7/// Combines the fully qualified class name (FQCN) and the method name.
8#[derive(Clone, Debug, PartialEq, Eq, Copy, Serialize, Deserialize, Hash, PartialOrd, Ord)]
9pub struct MethodIdentifier {
10    /// The fully qualified name of the class, interface, trait, or enum containing the method.
11    class_name: Atom,
12    /// The name of the method itself.
13    method_name: Atom,
14}
15
16impl MethodIdentifier {
17    /// Creates a new `MethodIdentifier`.
18    ///
19    /// # Arguments
20    ///
21    /// * `class_name`: The `Atom` for the fully qualified class name.
22    /// * `method_name`: The `Atom` for the method name.
23    #[inline]
24    #[must_use]
25    pub const fn new(class_name: Atom, method_name: Atom) -> Self {
26        Self { class_name, method_name }
27    }
28
29    /// Returns the `Atom` for the class name.
30    #[inline]
31    #[must_use]
32    pub const fn get_class_name(&self) -> &Atom {
33        &self.class_name
34    }
35
36    /// Returns the `Atom` for the method name.
37    #[inline]
38    #[must_use]
39    pub const fn get_method_name(&self) -> &Atom {
40        &self.method_name
41    }
42
43    /// Converts the identifier to a human-readable string "`ClassName::methodName`".
44    #[inline]
45    #[must_use]
46    pub fn as_string(&self) -> String {
47        format!("{}::{}", self.class_name, self.method_name)
48    }
49
50    /// Converts the identifier to a tuple of `Atom`s representing the class name and method name.
51    #[inline]
52    #[must_use]
53    pub fn get_key(&self) -> (Atom, Atom) {
54        (self.class_name, self.method_name)
55    }
56}