Skip to main content

weavatrix_graph/model/
span.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
4pub struct SourcePosition {
5    /// One-based line number.
6    pub line: u32,
7    /// One-based byte column.
8    pub column: u32,
9}
10
11impl SourcePosition {
12    #[must_use]
13    pub const fn new(line: u32, column: u32) -> Self {
14        Self { line, column }
15    }
16}
17
18#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
19pub struct SourceSpan {
20    pub file: String,
21    pub start: SourcePosition,
22    /// Exclusive end position.
23    pub end: SourcePosition,
24}
25
26impl SourceSpan {
27    #[must_use]
28    pub fn new(file: impl Into<String>, start: SourcePosition, end: SourcePosition) -> Self {
29        Self {
30            file: file.into(),
31            start,
32            end,
33        }
34    }
35}