Skip to main content

varyk_syntax/
span.rs

1//! Source spans: a file id plus a byte range within that file.
2
3/// Identifies a source file within a compilation. A small newtype over
4/// `u32` so file ids stay cheap to copy and compare.
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6pub struct FileId(pub u32);
7
8/// A byte range `[start, end)` within a single source file.
9#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
10pub struct Span {
11    pub file: FileId,
12    pub start: u32,
13    pub end: u32,
14}
15
16impl Span {
17    pub fn new(file: FileId, start: u32, end: u32) -> Self {
18        Self { file, start, end }
19    }
20}