dagrs_derive/
lib.rs

1use proc_macro::TokenStream;
2#[cfg(feature = "derive")]
3mod auto_node;
4mod relay;
5
6/// [`auto_node`] is a macro that may be used when customizing nodes. It can only be
7/// marked on named struct or unit struct.
8///
9/// The macro [`auto_node`] generates essential fields and implementation of traits for
10/// structs intended to represent `Node` in **Dagrs**.
11/// By applying this macro to a struct, it appends fields including `id: dagrs::NodeId`,
12/// `name: dagrs::NodeName`, `input_channels: dagrs::InChannels`, `output_channels: dagrs::OutChannels`,
13/// and `action: dagrs::Action`, and implements the required `dagrs::Node` trait.
14///
15/// ## Example
16/// - Mark `auto_node` on a struct with customized fields.
17/// ```ignore
18/// use dagrs::auto_node;
19/// #[auto_node]
20/// struct MyNode {/*Put your customized fields here.*/}
21/// ```
22///
23/// - Mark `auto_node` on a struct with generic & lifetime params.
24/// ```ignore
25/// use dagrs::auto_node;
26/// #[auto_node]
27/// struct MyNode<T, 'a> {/*Put your customized fields here.*/}
28/// ```
29/// - Mark `auto_node` on a unit struct.
30/// ```ignore
31/// use dagrs::auto_node;
32/// #[auto_node]
33/// struct MyNode()
34/// ```
35#[cfg(feature = "derive")]
36#[proc_macro_attribute]
37pub fn auto_node(args: TokenStream, input: TokenStream) -> TokenStream {
38    use crate::auto_node::auto_node;
39    auto_node(args, input).into()
40}
41
42/// The [`dependencies!`] macro allows users to specify all task dependencies in an easy-to-understand
43/// way. It will return the generated graph structure based on a set of defined dependencies
44#[cfg(feature = "derive")]
45#[proc_macro]
46pub fn dependencies(input: TokenStream) -> TokenStream {
47    use relay::add_relay;
48    use relay::Relaies;
49    let relaies = syn::parse_macro_input!(input as Relaies);
50    let token = add_relay(relaies);
51    token.into()
52}