40 lines
733 B
Rust
40 lines
733 B
Rust
|
use std::error::Error;
|
||
|
|
||
|
#[derive(Debug, Clone, Copy)]
|
||
|
pub struct Location<'a> {
|
||
|
pub line: usize,
|
||
|
pub col: usize,
|
||
|
pub file: Option<&'a str>,
|
||
|
}
|
||
|
|
||
|
#[derive(Debug, Clone)]
|
||
|
pub struct OwnedLocation {
|
||
|
pub line: usize,
|
||
|
pub col: usize,
|
||
|
pub file: Option<String>,
|
||
|
}
|
||
|
|
||
|
impl<'a> From<Location<'a>> for OwnedLocation {
|
||
|
fn from(l: Location<'a>) -> OwnedLocation {
|
||
|
OwnedLocation {
|
||
|
line: l.line,
|
||
|
col: l.col,
|
||
|
file: l.file.map(|v| v.to_string()),
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl<'a> From<&'a OwnedLocation> for Location<'a> {
|
||
|
fn from(l: &'a OwnedLocation) -> Location<'a> {
|
||
|
Location {
|
||
|
line: l.line,
|
||
|
col: l.col,
|
||
|
file: l.file.as_ref().map(|v| v.as_str()),
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pub trait ErrorWithLocation: Error {
|
||
|
fn get_location(&self) -> Location;
|
||
|
}
|