Skip to main content

hydro2_network_wire_derive/
lib.rs

1// ---------------- [ File: src/lib.rs ]
2#![allow(unused)]
3
4//! lib.rs — The `hydro2-network-wire-derive` crate implementing `[derive(NetworkWire)]`.
5#[macro_use] mod imports; use imports::*;
6
7// ----------------------------------------------------------------------
8//  The main macro entry point
9// ----------------------------------------------------------------------
10#[proc_macro_derive(NetworkWire, attributes(available_operators))]
11pub fn derive_network_wire(input: RawTokenStream) -> RawTokenStream {
12    let input_ast = parse_macro_input!(input as DeriveInput);
13
14    let (mut op_items, wire_generics) = match parse_available_operators_attribute(&input_ast) {
15        Ok((ops, gens)) => (ops, gens),
16        Err(ts) => return ts.into(),
17    };
18
19    let struct_ident = &input_ast.ident;
20
21    let (impl_generics, ty_generics, where_clause) = wire_generics.split_for_impl();
22    let enum_ident = syn::Ident::new(&format!("{}IO", struct_ident), struct_ident.span());
23
24    // Build the enum, then the bridging impls
25    let (enum_def,variant_idents) = build_network_io_enum(
26        &enum_ident,
27        &op_items,
28        &quote! { #impl_generics },
29        &quote! { #ty_generics },
30        &quote! { #where_clause }
31    );
32
33    let port_try_into_for_enum_def = build_port_try_into_impl(
34        &enum_ident,
35        &wire_generics,
36        &variant_idents,
37    );
38
39    let bridging_impls = build_bridging_impls(&enum_ident, &mut op_items, &wire_generics);
40
41    let expanded = quote! {
42        #enum_def
43        #port_try_into_for_enum_def
44        #( #bridging_impls )*
45    };
46    expanded.into()
47}
48
49xp!{angle_arg}
50xp!{parse_strings}
51xp!{build_operator_type_args}
52xp!{build_bridging_impls}
53xp!{build_network_io_enum}
54xp!{build_operator_signature_map}
55xp!{build_single_operator_impl}
56xp!{combine_where_clauses}
57xp!{extract_generics_from_path}
58xp!{finalize_operator_io_path}
59xp!{find_operator_signature_ident}
60xp!{maybe_reuse_lifetime}
61xp!{maybe_reuse_type_or_const}
62xp!{merge_generics}
63xp!{mint_const_param}
64xp!{mint_lifetime_param}
65xp!{mint_type_param}
66xp!{operator_items_parser}
67xp!{operator_spec_item}
68xp!{parse_available_operators_from_attribute}
69xp!{split_op_generics}
70xp!{split_wire_generics}
71xp!{try_reuse_wire_params}
72xp!{unify_generics_ast}
73xp!{build_port_try_into_impl}