Skip to main content

darklua_core/nodes/types/
type_field.rs

1use crate::nodes::{Identifier, Token};
2
3use super::TypeName;
4
5/// Represents a field access on a type.
6#[derive(Clone, Debug, PartialEq, Eq)]
7pub struct TypeField {
8    namespace: Identifier,
9    name: TypeName,
10    token: Option<Token>,
11}
12
13impl TypeField {
14    /// Creates a new type field with the specified namespace and type name.
15    pub fn new(namespace: impl Into<Identifier>, type_name: TypeName) -> Self {
16        Self {
17            namespace: namespace.into(),
18            name: type_name,
19            token: None,
20        }
21    }
22
23    /// Returns the type name part of this field access.
24    pub fn get_type_name(&self) -> &TypeName {
25        &self.name
26    }
27
28    /// Returns a mutable reference to the type name part of this field access.
29    pub fn mutate_type_name(&mut self) -> &mut TypeName {
30        &mut self.name
31    }
32
33    /// Returns the namespace identifier of this field access.
34    pub fn get_namespace(&self) -> &Identifier {
35        &self.namespace
36    }
37
38    /// Returns a mutable reference to the namespace identifier of this field access.
39    pub fn mutate_namespace(&mut self) -> &mut Identifier {
40        &mut self.namespace
41    }
42
43    /// Associates a token with this type field and returns the modified field.
44    pub fn with_token(mut self, token: Token) -> Self {
45        self.token = Some(token);
46        self
47    }
48
49    /// Sets the token associated with this type field.
50    #[inline]
51    pub fn set_token(&mut self, token: Token) {
52        self.token = Some(token);
53    }
54
55    /// Returns the token associated with this type field, if any.
56    #[inline]
57    pub fn get_token(&self) -> Option<&Token> {
58        self.token.as_ref()
59    }
60
61    pub fn mutate_last_token(&mut self) -> &mut Token {
62        self.name.mutate_last_token()
63    }
64
65    super::impl_token_fns!(target = [namespace] iter = [token]);
66}