ligen_core/generator/context/
source_file.rs1use serde::{Deserialize, Serialize};
4use std::path::PathBuf;
5
6#[cfg(cargo_ligen)]
7use crate::proc_macro;
8
9#[derive(Debug, Default, Serialize, Deserialize)]
10pub struct SourceFile {
12 is_real: bool,
13 path: PathBuf,
14}
15
16impl SourceFile {
17 #[cfg(cargo_ligen)]
18 pub fn current() -> Self {
20 proc_macro::Span::call_site().source_file().into()
21 }
22
23 pub fn is_real(&self) -> bool { self.is_real }
25
26 pub fn path(&self) -> PathBuf { self.path.clone() }
28}
29
30#[cfg(cargo_ligen)]
31impl From<proc_macro::SourceFile> for SourceFile {
32 fn from(source_file: proc_macro::SourceFile) -> Self {
33 let path = source_file.path();
34 let is_real = source_file.is_real();
35 Self { path, is_real }
36 }
37}