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