miden_core/debuginfo/
location.rs1use alloc::sync::Arc;
2use core::{fmt, ops::Range};
3
4use super::ByteIndex;
5
6#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
8pub struct Location {
9 pub path: Arc<str>,
11 pub start: ByteIndex,
13 pub end: ByteIndex,
15}
16
17impl Location {
18 pub const fn new(path: Arc<str>, start: ByteIndex, end: ByteIndex) -> Self {
20 Self { path, start, end }
21 }
22
23 pub fn path(&self) -> Arc<str> {
25 self.path.clone()
26 }
27
28 pub const fn range(&self) -> Range<ByteIndex> {
30 self.start..self.end
31 }
32}
33
34#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
36pub struct FileLineCol {
37 pub path: Arc<str>,
39 pub line: u32,
41 pub column: u32,
43}
44
45impl FileLineCol {
46 pub const fn new(path: Arc<str>, line: u32, column: u32) -> Self {
48 Self { path, line, column }
49 }
50
51 pub fn path(&self) -> Arc<str> {
53 self.path.clone()
54 }
55
56 pub const fn line(&self) -> u32 {
58 self.line
59 }
60
61 pub fn move_column(&mut self, offset: u32) {
63 self.column += offset;
64 }
65}
66
67impl fmt::Display for FileLineCol {
68 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
69 write!(f, "[{}@{}:{}]", &self.path, self.line, self.column)
70 }
71}