miden_debug_types/
location.rs1use core::{fmt, ops::Range};
2
3#[cfg(feature = "serde")]
4use serde::{Deserialize, Serialize};
5
6use super::{
7 ByteIndex, Uri,
8 source_file::{ColumnNumber, LineNumber},
9};
10
11#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
13#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
14pub struct Location {
15 pub uri: Uri,
17 pub start: ByteIndex,
19 pub end: ByteIndex,
21}
22
23impl Location {
24 pub const fn new(uri: Uri, start: ByteIndex, end: ByteIndex) -> Self {
26 Self { uri, start, end }
27 }
28
29 pub fn uri(&self) -> &Uri {
31 &self.uri
32 }
33
34 pub const fn range(&self) -> Range<ByteIndex> {
36 self.start..self.end
37 }
38}
39
40#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
42#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
43pub struct FileLineCol {
44 pub uri: Uri,
46 pub line: LineNumber,
48 pub column: ColumnNumber,
50}
51
52impl FileLineCol {
53 pub fn new(
55 uri: impl Into<Uri>,
56 line: impl Into<LineNumber>,
57 column: impl Into<ColumnNumber>,
58 ) -> Self {
59 Self {
60 uri: uri.into(),
61 line: line.into(),
62 column: column.into(),
63 }
64 }
65
66 pub fn uri(&self) -> &Uri {
68 &self.uri
69 }
70
71 pub const fn line(&self) -> LineNumber {
73 self.line
74 }
75
76 pub fn move_column(&mut self, offset: i32) {
78 self.column += offset;
79 }
80}
81
82impl fmt::Display for FileLineCol {
83 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
84 write!(f, "[{}@{}:{}]", &self.uri, self.line, self.column)
85 }
86}