darklua_core/nodes/types/
variadic_type_pack.rs

1use crate::nodes::Token;
2
3use super::Type;
4
5/// Represents a variadic type pack in Luau.
6///
7/// Variadic type packs represent an arbitrary number of values of the same type,
8/// written with a leading `...` and a type.
9#[derive(Clone, Debug, PartialEq, Eq)]
10pub struct VariadicTypePack {
11    // ... type
12    inner_type: Box<Type>,
13    token: Option<Token>,
14}
15
16impl VariadicTypePack {
17    /// Creates a new variadic type pack with the specified element type.
18    pub fn new(r#type: impl Into<Type>) -> Self {
19        Self {
20            inner_type: Box::new(r#type.into()),
21            token: None,
22        }
23    }
24
25    /// Returns the element type of this variadic type pack.
26    #[inline]
27    pub fn get_type(&self) -> &Type {
28        &self.inner_type
29    }
30
31    /// Returns a mutable reference to the element type of this variadic type pack.
32    #[inline]
33    pub fn mutate_type(&mut self) -> &mut Type {
34        &mut self.inner_type
35    }
36
37    /// Associates a token with this variadic type pack.
38    pub fn with_token(mut self, token: Token) -> Self {
39        self.token = Some(token);
40        self
41    }
42
43    /// Sets the `...` token preceding this variadic type pack.
44    #[inline]
45    pub fn set_token(&mut self, token: Token) {
46        self.token = Some(token);
47    }
48
49    /// Returns the `...` token preceding this variadic type pack, if any.
50    #[inline]
51    pub fn get_token(&self) -> Option<&Token> {
52        self.token.as_ref()
53    }
54
55    /// Returns a mutable reference to the `...` token preceding this variadic type pack, if any.
56    #[inline]
57    pub fn mutate_token(&mut self) -> Option<&mut Token> {
58        self.token.as_mut()
59    }
60
61    pub fn mutate_last_token(&mut self) -> &mut Token {
62        self.inner_type.mutate_last_token()
63    }
64
65    super::impl_token_fns!(iter = [token]);
66}