1use std::fmt;
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub struct Range {
8 pub start: i32,
9 pub end: i32,
10}
11
12impl Range {
13 pub fn new(start: i32, end: i32) -> Self {
15 Self { start, end }
16 }
17
18 pub fn all() -> Self {
20 Self { start: i32::MIN, end: i32::MAX }
21 }
22
23 pub fn size(&self) -> i32 {
25 self.end - self.start
26 }
27
28 pub fn empty(&self) -> bool {
30 self.start >= self.end
31 }
32}
33
34impl Default for Range {
35 fn default() -> Self {
36 Self::all()
37 }
38}
39
40impl fmt::Display for Range {
41 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
42 write!(f, "[{}, {})", self.start, self.end)
43 }
44}