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