MCPcopy Create free account
hub / github.com/MegEngine/MegFlow / expand

Function expand

flow-derive/src/node.rs:46–147  ·  view source on GitHub ↗
(input: DeriveInput)

Source from the content-addressed store, hash-verified

44}
45
46pub fn expand(input: DeriveInput) -> TokenStream {
47 let ident = input.ident;
48 type IterArgs<'a> = ExtractParams<'a>;
49 fn set_f((port_func, ident, ty): IterArgs) -> TokenStream {
50 if match_last_ty(ty, "Vec") {
51 quote_spanned! {ident.span()=>
52 if port_name == concat!('[', stringify!(#ident), ']') {
53 self.#ident.push(channel.#port_func());
54 } else
55 }
56 } else if match_last_ty(ty, "HashMap") {
57 quote_spanned! {ident.span()=>
58 if port_name == concat!('{', stringify!(#ident), '}') {
59 self.#ident.insert(tag.expect("dict port need a tag"), channel.#port_func());
60 } else
61 }
62 } else if match_last_ty(ty, "DynPorts") {
63 quote! {}
64 } else {
65 quote_spanned! {ident.span()=>
66 if port_name == stringify!(#ident) {
67 self.#ident = channel.#port_func();
68 } else
69 }
70 }
71 }
72 fn set_dyn_f((_, ident, ty): IterArgs) -> TokenStream {
73 if match_last_ty(ty, "DynPorts") {
74 quote_spanned! {ident.span()=>
75 if port_name == concat!("dyn@", stringify!(#ident)) {
76 self.#ident = flow_rs::node::DynPorts::new(cfg);
77 } else
78 }
79 } else {
80 quote! {}
81 }
82 }
83 fn close_f((_, ident, ty): IterArgs) -> TokenStream {
84 if match_last_ty(ty, "Vec") || match_last_ty(ty, "HashMap") {
85 quote_spanned! {ident.span()=>
86 self.#ident.clear();
87 }
88 } else {
89 quote!()
90 }
91 }
92 fn is_close_f((_, ident, ty): IterArgs) -> TokenStream {
93 if match_last_ty(ty, "Vec") {
94 quote_spanned! {ident.span()=>
95 for chan in &self.#ident {
96 is_closed = is_closed && chan.is_closed();
97 }
98 }
99 } else if match_last_ty(ty, "HashMap") {
100 quote_spanned! {ident.span()=>
101 for chan in self.#ident.values() {
102 is_closed = is_closed && chan.is_closed();
103 }

Callers 2

node_deriveFunction · 0.70
actor_deriveFunction · 0.70

Calls 1

extract_portsFunction · 0.85

Tested by

no test coverage detected