1use serde::{Deserialize, Serialize};
2
3#[derive(
6 Debug, Clone, Copy, Default, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize,
7)]
8#[serde(from = "[u32; 4]", into = "[u32; 4]")]
9pub struct Range {
10 pub start_line: u32,
11 pub start_col: u32,
12 pub end_line: u32,
13 pub end_col: u32,
14}
15
16impl Range {
17 pub fn new(start_line: u32, start_col: u32, end_line: u32, end_col: u32) -> Self {
18 Range {
19 start_line,
20 start_col,
21 end_line,
22 end_col,
23 }
24 }
25
26 pub fn contains(&self, line: u32, col: u32) -> bool {
27 (self.start_line, self.start_col) <= (line, col)
28 && (line, col) < (self.end_line, self.end_col)
29 }
30}
31
32impl From<[u32; 4]> for Range {
33 fn from([a, b, c, d]: [u32; 4]) -> Self {
34 Range::new(a, b, c, d)
35 }
36}
37
38impl From<Range> for [u32; 4] {
39 fn from(r: Range) -> Self {
40 [r.start_line, r.start_col, r.end_line, r.end_col]
41 }
42}