1use std::{path::PathBuf, sync::Arc};
4
5#[derive(Clone, Debug, Default)]
7#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
8pub struct SourceInfo {
9 pub source: String,
11 pub start: Option<Arc<crate::SourcePosition>>,
14}
15
16impl From<&str> for SourceInfo {
17 fn from(source: &str) -> Self {
18 Self {
19 source: source.to_owned(),
20 start: None,
21 }
22 }
23}
24
25impl From<PathBuf> for SourceInfo {
26 fn from(path: PathBuf) -> Self {
27 Self {
28 source: path.to_string_lossy().to_string(),
29 start: None,
30 }
31 }
32}
33
34impl std::fmt::Display for SourceInfo {
35 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36 write!(f, "{}", self.source)?;
37
38 if let Some(pos) = &self.start {
39 write!(f, ":{},{}", pos.line, pos.column)?;
40 }
41
42 Ok(())
43 }
44}