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