Skip to main content

qutonium/core/
sourcer.rs

1use std::fmt::{Display, Formatter, Result};
2
3
4#[derive(Clone, Copy, Debug)]
5pub struct Location {
6  pub column: u32,
7  pub file: &'static str,
8  pub line: u32,
9}
10
11
12impl Location {
13  pub fn new (file: &'static str, line: u32, column: u32) -> Self {
14    Location { column, file, line }
15  }
16}
17
18
19#[derive(Clone, Copy, Debug)]
20pub struct Source {
21  pub location: Location,
22}
23
24
25impl Display for Source {
26  fn fmt (&self, f: &mut Formatter<'_>) -> Result {
27    let Location { column, file, line } = self.location;
28
29    write!(f, "{}:{}:{}", file, line, column)
30  }
31}
32
33
34impl Source {
35  pub fn new (location: Location) -> Self {
36    Source { location }
37  }
38}