cypher_dto_macros/
lib.rs

1use proc_macro::TokenStream;
2
3mod derive;
4mod timestamps;
5
6use derive::{Node, Relation};
7use syn::{parse_macro_input, DeriveInput};
8
9/// Derives the [NodeEntity](::cypher_dto::NodeEntity) and related traits.
10#[proc_macro_derive(Node, attributes(name, id, labels))]
11pub fn derive_node(input: TokenStream) -> TokenStream {
12    let input = parse_macro_input!(input as DeriveInput);
13    Node::new(input).to_token_stream()
14}
15
16/// Derives the [RelationEntity](::cypher_dto::RelationEntity) and related traits.
17#[proc_macro_derive(Relation, attributes(name, id))]
18pub fn derive_relation(input: TokenStream) -> TokenStream {
19    let input = parse_macro_input!(input as DeriveInput);
20    Relation::new(input).to_token_stream()
21}
22
23/// Adds created/updated timestamp fields to a struct, using [`Option<DateTime<Utc>>`] as the type.
24///
25/// The default field names are `created_at` and `updated_at`, but can be changed
26/// by passing a string to the `#[timestamps]` attribute.
27///
28/// On structs marked with `#[derive(Node)]` or `#[derive(Relation)]`,
29/// their `::new()` implementation already checks for Optional timestamp fields will set them to `None`.
30#[proc_macro_attribute]
31pub fn timestamps(args: TokenStream, input: TokenStream) -> TokenStream {
32    timestamps::stamps_impl(args, input)
33}