formualizer_common/
range.rs1#[derive(Clone, Debug, PartialEq, Eq, Hash)]
2pub struct RangeAddress {
3 pub sheet: String,
4 pub start_row: u32,
5 pub start_col: u32,
6 pub end_row: u32,
7 pub end_col: u32,
8}
9
10impl RangeAddress {
11 pub fn new(
12 sheet: impl Into<String>,
13 start_row: u32,
14 start_col: u32,
15 end_row: u32,
16 end_col: u32,
17 ) -> Result<Self, &'static str> {
18 if start_row == 0 || start_col == 0 || end_row == 0 || end_col == 0 {
19 return Err("Row and column indices must be 1-based");
20 }
21 if start_row > end_row || start_col > end_col {
22 return Err("Range must be ordered: start <= end");
23 }
24 Ok(Self {
25 sheet: sheet.into(),
26 start_row,
27 start_col,
28 end_row,
29 end_col,
30 })
31 }
32
33 pub fn width(&self) -> u32 {
34 self.end_col - self.start_col + 1
35 }
36 pub fn height(&self) -> u32 {
37 self.end_row - self.start_row + 1
38 }
39}