factorio_ir/meta/
origin.rs1use std::sync::Arc;
4
5#[derive(Debug, Clone, PartialEq, Eq, Hash)]
7pub struct Origin {
8 pub file: Arc<str>,
9 pub line: u32,
10 pub column: u32,
11}
12
13impl Origin {
14 #[must_use]
15 pub fn new(file: impl Into<Arc<str>>, line: u32, column: u32) -> Self {
16 Self {
17 file: file.into(),
18 line,
19 column: column.max(1),
20 }
21 }
22
23 #[must_use]
25 pub fn display(&self) -> String {
26 if self.column <= 1 {
27 format!("{}:{}", self.file, self.line)
28 } else {
29 format!("{}:{}:{}", self.file, self.line, self.column)
30 }
31 }
32}