Skip to main content

oxanus_macros/
lib.rs

1mod queue;
2mod registry;
3mod worker;
4
5use queue::*;
6use registry::*;
7use worker::*;
8
9use proc_macro::TokenStream;
10use proc_macro_error2::proc_macro_error;
11use syn::{DeriveInput, parse_macro_input};
12
13/// Generates impl for `oxanus::Queue`.
14///
15/// Example usage:
16/// ```ignore
17/// #[derive(Serialize, oxanus::Queue)]
18/// #[oxanus(key = "my_queue")]
19/// #[oxanus(concurrency = 2)]
20/// #[oxanus(throttle(window_ms = 3, limit = 4))]
21/// pub struct MyQueue;
22/// ```
23#[proc_macro_error]
24#[proc_macro_derive(Queue, attributes(oxanus))]
25pub fn derive_queue(input: TokenStream) -> TokenStream {
26    let input = parse_macro_input!(input as DeriveInput);
27
28    expand_derive_queue(input).into()
29}
30
31/// Generates impl for `oxanus::Worker`.
32///
33/// Example usage:
34/// ```ignore
35/// #[derive(Serialize, oxanus::Worker)]
36/// #[oxanus(max_retries = 3, on_conflict = Replace)]
37/// #[oxanus(unique_id = "test_worker_{id}")]
38/// struct TestWorkerUniqueId {
39///     id: i32,
40/// }
41/// ```
42#[proc_macro_error]
43#[proc_macro_derive(Worker, attributes(oxanus))]
44pub fn derive_worker(input: TokenStream) -> TokenStream {
45    let input = parse_macro_input!(input as DeriveInput);
46
47    expand_derive_worker(input).into()
48}
49
50/// Helper to define a component registry.
51#[proc_macro_error]
52#[proc_macro_derive(Registry, attributes(oxanus))]
53pub fn derive_registry(input: TokenStream) -> TokenStream {
54    let input = parse_macro_input!(input as DeriveInput);
55
56    expand_derive_registry(input).into()
57}