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 pub const fn new(class_name: Atom, method_name: Atom) -> Self {
25 Self { class_name, method_name }
26 }
27
28 /// Returns the `Atom` for the class name.
29 #[inline]
30 pub const fn get_class_name(&self) -> &Atom {
31 &self.class_name
32 }
33
34 /// Returns the `Atom` for the method name.
35 #[inline]
36 pub const fn get_method_name(&self) -> &Atom {
37 &self.method_name
38 }
39
40 /// Converts the identifier to a human-readable string "ClassName::methodName".
41 #[inline]
42 pub fn as_string(&self) -> String {
43 format!("{}::{}", self.class_name, self.method_name)
44 }
45
46 /// Converts the identifier to a tuple of `Atom`s representing the class name and method name.
47 #[inline]
48 pub fn get_key(&self) -> (Atom, Atom) {
49 (self.class_name, self.method_name)
50 }
51}