brisk_it/
lib.rs

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
//! brisk-it is a macro-based system for transforming a declarative representation into
//! imperative Rust code. Its main application is currently for developing [egui](https://www.egui.rs/)
//! user interface.

#![warn(missing_docs)]
#![deny(warnings)]

extern crate proc_macro;

pub mod component;
pub mod errors;
pub mod generator;
mod utils_impl;

pub use utils_impl::Either;
pub use utils_impl::Required;

/// Utility module.
pub mod utils {
    pub use crate::utils_impl::blockify;
    pub use crate::utils_impl::component_or_expression;
}

/// Result type, which return a token stream with the error
pub type Result<T> = std::result::Result<T, proc_macro2::TokenStream>;

use proc_macro::TokenStream;
use syn::parse_macro_input;

/// This is the core entry point of the brisk library. It should be used in a macro-proc to
/// trigger the transformation between the declarative representation and generate the Rust code.
pub fn brisk_it(
    input: proc_macro::TokenStream,
    generator_manager: &generator::Manager,
) -> TokenStream {
    let input = parse_macro_input!(input as component::ComponentInput);
    let output = generator_manager.generate(input).either();
    // println!("----\n\n\n\n{}\n\n\n\n----", output.to_string());
    output.into()
}