use alloc::string::{String, ToString};
use alloc::vec::Vec;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct ByteSpan {
pub start: u32,
pub end: u32,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct MacroExpansion {
pub name: String,
pub invoked_at: Option<ByteSpan>,
pub path: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum SourceOrigin {
File {
path: String,
},
Synthetic {
reason: String,
},
Builtin,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SourceFacet {
pub origin: SourceOrigin,
pub span: Option<ByteSpan>,
pub macro_chain: Vec<MacroExpansion>,
pub doc_comments: Vec<String>,
}
impl SourceFacet {
#[must_use]
pub fn synthetic(reason: &str) -> Self {
Self {
origin: SourceOrigin::Synthetic {
reason: reason.to_string(),
},
span: None,
macro_chain: Vec::new(),
doc_comments: Vec::new(),
}
}
#[must_use]
pub const fn builtin() -> Self {
Self {
origin: SourceOrigin::Builtin,
span: None,
macro_chain: Vec::new(),
doc_comments: Vec::new(),
}
}
#[must_use]
pub fn file(path: String, span: Option<ByteSpan>) -> Self {
Self {
origin: SourceOrigin::File { path },
span,
macro_chain: Vec::new(),
doc_comments: Vec::new(),
}
}
#[must_use]
pub const fn is_from_file(&self) -> bool {
matches!(self.origin, SourceOrigin::File { .. })
}
}
impl Default for SourceFacet {
fn default() -> Self {
Self::synthetic("created through the model API")
}
}