Skip to main content

ephemeris_documents/yaml/source/read/
bounds.rs

1//! Byte offsets of a node in the source text.
2
3/// The start and end offset of a piece of the source.
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub(super) struct Bounds {
6    pub(super) start: usize,
7    pub(super) end: usize,
8}
9
10impl Bounds {
11    pub(super) const fn new(start: usize, end: usize) -> Self {
12        Self { start, end }
13    }
14
15    /// The smallest bounds that hold both.
16    pub(super) fn cover(self, other: Self) -> Self {
17        Self {
18            start: self.start.min(other.start),
19            end: self.end.max(other.end),
20        }
21    }
22
23    pub(super) const fn is_empty(self) -> bool {
24        self.start == self.end
25    }
26}