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