air_script_core/
access.rs

1use super::Identifier;
2
3/// [VectorAccess] is used to represent an element inside vector at the specified index.
4#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Clone)]
5pub struct VectorAccess {
6    name: Identifier,
7    idx: usize,
8}
9
10impl VectorAccess {
11    /// Creates a new [VectorAccess] instance with the specified identifier name and index.
12    pub fn new(name: Identifier, idx: usize) -> Self {
13        Self { name, idx }
14    }
15
16    /// Returns the name of the vector.
17    pub fn name(&self) -> &str {
18        self.name.name()
19    }
20
21    /// Returns the index of the vector access.
22    pub fn idx(&self) -> usize {
23        self.idx
24    }
25}
26
27/// [MatrixAccess] is used to represent an element inside a matrix at the specified row and column
28/// indices.
29#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Clone)]
30pub struct MatrixAccess {
31    name: Identifier,
32    row_idx: usize,
33    col_idx: usize,
34}
35
36impl MatrixAccess {
37    /// Creates a new [MatrixAccess] instance with the specified identifier name and indices.
38    pub fn new(name: Identifier, row_idx: usize, col_idx: usize) -> Self {
39        Self {
40            name,
41            row_idx,
42            col_idx,
43        }
44    }
45
46    /// Returns the name of the matrix.
47    pub fn name(&self) -> &str {
48        self.name.name()
49    }
50
51    /// Returns the row index of the matrix access.
52    pub fn row_idx(&self) -> usize {
53        self.row_idx
54    }
55
56    /// Returns the column index of the matrix access.
57    pub fn col_idx(&self) -> usize {
58        self.col_idx
59    }
60}
61
62#[derive(Debug, Clone, Eq, PartialEq)]
63pub struct Range {
64    start: usize,
65    end: usize,
66}
67
68impl Range {
69    pub fn new(start: usize, end: usize) -> Self {
70        Self { start, end }
71    }
72
73    pub fn start(&self) -> usize {
74        self.start
75    }
76
77    pub fn end(&self) -> usize {
78        self.end
79    }
80}