spo_rhai/types/
var_def.rs

1//! Variable declaration information.
2
3#[cfg(feature = "no_std")]
4use std::prelude::v1::*;
5
6/// Information on a variable declaration.
7#[derive(Debug, Clone, Hash)]
8pub struct VarDefInfo<'a> {
9    /// Name of the variable to be declared.
10    ///
11    /// # Deprecated API
12    ///
13    /// [`VarDefInfo`] fields will be private in the next major version. Use `name()` instead.
14    #[deprecated(
15        since = "1.16.0",
16        note = "`VarDefInfo` fields will be private in the next major version. Use `name()` instead."
17    )]
18    pub name: &'a str,
19    /// `true` if the statement is `const`, otherwise it is `let`.
20    ///
21    /// # Deprecated API
22    ///
23    /// [`VarDefInfo`] fields will be private in the next major version. Use `is_const()` instead.
24    #[deprecated(
25        since = "1.16.0",
26        note = "`VarDefInfo` fields will be private in the next major version. Use `is_const()` instead."
27    )]
28    pub is_const: bool,
29    /// The current nesting level, with zero being the global level.
30    ///
31    /// # Deprecated API
32    ///
33    /// [`VarDefInfo`] fields will be private in the next major version. Use `nesting_level()` instead.
34    #[deprecated(
35        since = "1.16.0",
36        note = "`VarDefInfo` fields will be private in the next major version. Use `nesting_level()` instead."
37    )]
38    pub nesting_level: usize,
39    /// Will the variable _shadow_ an existing variable?
40    ///
41    /// # Deprecated API
42    ///
43    /// [`VarDefInfo`] fields will be private in the next major version. Use `will_shadow_other_variables()` instead.
44    #[deprecated(
45        since = "1.16.0",
46        note = "`VarDefInfo` fields will be private in the next major version. Use `will_shadow_other_variables()` instead."
47    )]
48    pub will_shadow: bool,
49}
50
51#[allow(deprecated)]
52impl<'a> VarDefInfo<'a> {
53    /// Create a new [`VarDefInfo`].
54    #[inline(always)]
55    #[must_use]
56    pub(crate) const fn new(
57        name: &'a str,
58        is_const: bool,
59        nesting_level: usize,
60        will_shadow: bool,
61    ) -> Self {
62        Self {
63            name,
64            is_const,
65            nesting_level,
66            will_shadow,
67        }
68    }
69    /// Name of the variable to be declared.
70    #[inline(always)]
71    #[must_use]
72    pub const fn name(&self) -> &str {
73        self.name
74    }
75    /// `true` if the statement is `const`, otherwise it is `let`.
76    #[inline(always)]
77    #[must_use]
78    pub const fn is_const(&self) -> bool {
79        self.is_const
80    }
81    /// The current nesting level, with zero being the global level.
82    #[inline(always)]
83    #[must_use]
84    pub const fn nesting_level(&self) -> usize {
85        self.nesting_level
86    }
87    /// `true` if the variable is declared at global level (i.e. nesting level zero).
88    #[inline(always)]
89    #[must_use]
90    pub const fn is_global_level(&self) -> bool {
91        self.nesting_level == 0
92    }
93    /// Will the variable _shadow_ an existing variable?
94    #[inline(always)]
95    #[must_use]
96    pub const fn will_shadow_other_variables(&self) -> bool {
97        self.will_shadow
98    }
99}