ligen_core/generator/context/
mod.rs

1//! Context about the proc-macro execution.
2
3mod arguments;
4mod build_type;
5mod source_file;
6
7pub use arguments::*;
8pub use build_type::*;
9pub use source_file::*;
10
11#[cfg(cargo_ligen)]
12use crate::prelude::*;
13use serde::{Deserialize, Serialize};
14
15#[derive(Debug, Default, Serialize, Deserialize)]
16/// Context struct.
17pub struct Context {
18    /// The current SourceFile.
19    pub source_file: SourceFile,
20    /// Arguments.
21    pub arguments: Arguments,
22}
23
24impl Context {
25    #[cfg(cargo_ligen)]
26    /// Get the current generator context by getting the arguments from the environment varilables,
27    /// which might fail if they aren't correctly set from `cargo-ligen`.
28    pub fn current() -> Result<Self> {
29        let source_file = SourceFile::current();
30        let arguments = Arguments::from_env()?;
31        Ok(Self { source_file, arguments })
32    }
33}