embedded_command_macros/lib.rs
1use proc_macro::TokenStream;
2
3mod dispatch_bundle;
4mod serac;
5
6/// Transform attached enum into a "bundle".
7///
8/// *What is a bundle?*
9///
10/// Bundles are used to accomplish dynamic dispatch in resource constrained systems (no_std).
11/// A bundle can hold a finite number of types that implement a common trait.
12/// The size of the bundle is known at compile time and equal to the size of the largest type in the bundle.
13/// Bundles are useful for type-erasure when transporting multiple types pseudo-heterogeneously.
14#[proc_macro_attribute]
15pub fn bundle(attr: TokenStream, item: TokenStream) -> TokenStream {
16 dispatch_bundle::bundle(attr, item)
17}
18
19/// Generates the implementation block for conforming to `SerializeIter` of the "vanilla" flavor.
20///
21/// # Note
22///
23/// Requires `serac` to be in scope with that name.
24#[proc_macro_derive(SerializeIter)]
25pub fn impl_serialize_iter_vanilla(item: TokenStream) -> TokenStream {
26 serac::vanilla::serialize_iter(item)
27}
28
29/// Generates the implementation block for conforming to `Size` of the "vanilla" flavor.
30///
31/// # Note
32///
33/// Requires `serac` to be in scope with that name.
34#[proc_macro_derive(Size)]
35pub fn impl_size_vanilla(item: TokenStream) -> TokenStream {
36 serac::vanilla::impl_size(item)
37}
38
39/// Generates the implementation block for conforming to `SerializeBuf`.
40///
41/// As of now, generic types *cannot* implement `SerializeBuf` on stable.
42///
43/// # Note
44///
45/// Requires `serac` to be in scope with that name.
46#[proc_macro_derive(SerializeBuf)]
47pub fn impl_serialize_buf(item: TokenStream) -> TokenStream {
48 serac::impl_serialize_buf(item)
49}
50
51/// Generates the implementation block for conforming to `SerializeBuf` for a type
52/// alias. This is used for implementing `SerializeBuf` for concretely specified
53/// generic types.
54///
55/// # Note
56///
57/// Requires `serac` to be in scope with that name.
58#[proc_macro_attribute]
59pub fn impl_serialize_buf_alias(attrs: TokenStream, item: TokenStream) -> TokenStream {
60 serac::impl_serialize_buf_alias(attrs, item)
61}