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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#![deny(missing_debug_implementations)]
#![deny(rustdoc::broken_intra_doc_links)]

#[cfg(feature = "rust")]
mod rust;

pub mod error;

use aldrin_parser::Parsed;

pub use error::Error;
#[cfg(feature = "rust")]
pub use rust::{RustOptions, RustOutput};

#[derive(Debug)]
pub struct Generator<'a> {
    options: &'a Options,
    parsed: &'a Parsed,
}

impl<'a> Generator<'a> {
    pub fn new(options: &'a Options, parsed: &'a Parsed) -> Self {
        assert!(parsed.errors().is_empty());
        Generator { options, parsed }
    }

    pub fn options(&self) -> &'a Options {
        self.options
    }

    pub fn parsed(&self) -> &'a Parsed {
        self.parsed
    }

    #[cfg(feature = "rust")]
    pub fn generate_rust(&self, rust_options: &RustOptions) -> Result<RustOutput, Error> {
        rust::generate(self.parsed, self.options, rust_options)
    }
}

#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct Options {
    pub client: bool,
    pub server: bool,
}

impl Options {
    pub fn new() -> Self {
        Options {
            client: true,
            server: true,
        }
    }
}

impl Default for Options {
    fn default() -> Self {
        Options::new()
    }
}