restate_sdk_macros/
lib.rs

1// Copyright (c) 2023 -  Restate Software, Inc., Restate GmbH.
2// All rights reserved.
3//
4// Use of this software is governed by the Business Source License
5// included in the LICENSE file.
6//
7// As of the Change Date specified in that file, in accordance with
8// the Business Source License, use of this software will be governed
9// by the Apache License, Version 2.0.
10
11// Some parts of this codebase were taken from https://github.com/google/tarpc/blob/b826f332312d3702667880a464e247556ad7dbfe/plugins/src/lib.rs
12// License MIT
13
14extern crate proc_macro;
15
16mod ast;
17mod gen;
18
19use crate::ast::{Object, Service, Workflow};
20use crate::gen::ServiceGenerator;
21use proc_macro::TokenStream;
22use quote::ToTokens;
23use syn::parse_macro_input;
24
25#[proc_macro_attribute]
26pub fn service(_: TokenStream, input: TokenStream) -> TokenStream {
27    let svc = parse_macro_input!(input as Service);
28
29    ServiceGenerator::new_service(&svc)
30        .into_token_stream()
31        .into()
32}
33
34#[proc_macro_attribute]
35pub fn object(_: TokenStream, input: TokenStream) -> TokenStream {
36    let svc = parse_macro_input!(input as Object);
37
38    ServiceGenerator::new_object(&svc)
39        .into_token_stream()
40        .into()
41}
42
43#[proc_macro_attribute]
44pub fn workflow(_: TokenStream, input: TokenStream) -> TokenStream {
45    let svc = parse_macro_input!(input as Workflow);
46
47    ServiceGenerator::new_workflow(&svc)
48        .into_token_stream()
49        .into()
50}