Skip to main content

vgi_rpc_macros/
lib.rs

1//! Proc-macros for `vgi-rpc`.
2//!
3//! Re-exported from `vgi-rpc` (behind the default-on `macros` feature)
4//! so users only depend on `vgi-rpc` directly:
5//!
6//! ```ignore
7//! use vgi_rpc::{service, unary, producer, exchange, VgiArrow, StreamState};
8//! ```
9
10mod derive_arrow;
11mod derive_stream_state;
12mod service;
13
14use proc_macro::TokenStream;
15
16/// Derive `VgiArrow` for a struct, generating a `Struct<fields>` Arrow
17/// data type plus per-field read / build_singleton wiring.
18///
19/// Field types must themselves implement `VgiArrow`. Nullable fields
20/// use `Option<T>`. Override the describe-format type name with
21/// `#[vgi_arrow(name = "...")]`.
22///
23/// ```ignore
24/// use vgi_rpc::VgiArrow;
25///
26/// #[derive(VgiArrow)]
27/// #[vgi_arrow(name = "Point")]
28/// struct Point { x: f64, y: f64 }
29///
30/// #[derive(VgiArrow)]
31/// struct BoundingBox {
32///     top_left: Point,
33///     bottom_right: Point,
34///     label: String,
35/// }
36/// ```
37#[proc_macro_derive(VgiArrow, attributes(vgi_arrow))]
38pub fn derive_vgi_arrow(input: TokenStream) -> TokenStream {
39    derive_arrow::derive(input)
40}
41
42/// Derive `StreamStateCodec` (bincode-backed) and supply the
43/// `encode_state` forwarder for `ProducerState` / `ExchangeState`.
44///
45/// Adds an inherent `__vgi_encode_state(&self)` helper that the trait
46/// impl can call from `encode_state` in one line. Phase 4 of the macro
47/// pass will land this; this stub keeps the public symbol stable.
48#[proc_macro_derive(StreamState, attributes(stream_state))]
49pub fn derive_stream_state(input: TokenStream) -> TokenStream {
50    derive_stream_state::derive(input)
51}
52
53/// Service-level attribute applied to an `impl Block`. Scans methods
54/// tagged with `#[unary]`, `#[producer(...)]`, or `#[exchange(...)]`
55/// and generates a `register_with(server, instance)` impl.
56///
57/// Phase 3+ of the macro pass will land this; this stub returns the
58/// input unchanged so the public symbol is reserved.
59#[proc_macro_attribute]
60pub fn service(args: TokenStream, item: TokenStream) -> TokenStream {
61    service::expand(args, item)
62}
63
64/// No-op attribute consumed by `#[service]`. Standalone use is a
65/// compile error in V1.
66#[proc_macro_attribute]
67pub fn unary(_args: TokenStream, item: TokenStream) -> TokenStream {
68    service::passthrough(item)
69}
70
71/// No-op attribute consumed by `#[service]`. Standalone use is a
72/// compile error in V1.
73#[proc_macro_attribute]
74pub fn producer(_args: TokenStream, item: TokenStream) -> TokenStream {
75    service::passthrough(item)
76}
77
78/// No-op attribute consumed by `#[service]`. Standalone use is a
79/// compile error in V1.
80#[proc_macro_attribute]
81pub fn exchange(_args: TokenStream, item: TokenStream) -> TokenStream {
82    service::passthrough(item)
83}
84
85/// No-op attribute consumed by `#[service]` for per-parameter metadata.
86#[proc_macro_attribute]
87pub fn param(_args: TokenStream, item: TokenStream) -> TokenStream {
88    service::passthrough(item)
89}