aldrin_codegen/
lib.rs

1#![deny(missing_debug_implementations)]
2
3#[cfg(feature = "rust")]
4mod rust;
5
6pub mod error;
7
8use aldrin_parser::Parsed;
9
10pub use error::Error;
11#[cfg(feature = "rust")]
12pub use rust::{RustOptions, RustOutput};
13
14#[derive(Debug)]
15pub struct Generator<'a> {
16    options: &'a Options,
17    parsed: &'a Parsed,
18}
19
20impl<'a> Generator<'a> {
21    pub fn new(options: &'a Options, parsed: &'a Parsed) -> Self {
22        assert!(parsed.errors().is_empty());
23        Generator { options, parsed }
24    }
25
26    pub fn options(&self) -> &'a Options {
27        self.options
28    }
29
30    pub fn parsed(&self) -> &'a Parsed {
31        self.parsed
32    }
33
34    #[cfg(feature = "rust")]
35    pub fn generate_rust(&self, rust_options: &RustOptions) -> Result<RustOutput, Error> {
36        rust::generate(self.parsed, self.options, rust_options)
37    }
38}
39
40#[derive(Debug, Clone)]
41#[non_exhaustive]
42pub struct Options {
43    pub client: bool,
44    pub server: bool,
45    pub introspection: bool,
46}
47
48impl Options {
49    pub fn new() -> Self {
50        Self {
51            client: true,
52            server: true,
53            introspection: false,
54        }
55    }
56}
57
58impl Default for Options {
59    fn default() -> Self {
60        Self::new()
61    }
62}