1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
//! Provides proc_macros for toy-rpc.

use proc_macro::TokenStream;
use quote::{ToTokens, quote};
use syn::{GenericArgument, Ident, parse_macro_input, parse_quote};

const SERVICE_PREFIX: &str = "STATIC_TOY_RPC_SERVICE";
const ATTR_EXPORT_METHOD: &str = "export_method";
const HANDLER_SUFFIX: &str = "handler";
const CLIENT_SUFFIX: &str = "Client";
const CLIENT_STUB_SUFFIX: &str = "ClientStub";

/// A macro that impls serde::Deserializer by simply calling the
/// corresponding functions of the inner deserializer
#[proc_macro]
pub fn impl_inner_deserializer(_: TokenStream) -> TokenStream {
    let output = quote! {
        fn deserialize_any<V>(mut self, visitor: V) -> Result<V::Value, Self::Error>
        where
                V: Visitor<'de> {
            self.inner.deserialize_any(visitor)
        }

        fn deserialize_bool<V>(mut self, visitor: V) -> Result<V::Value, Self::Error>
        where
                V: Visitor<'de> {
            self.inner.deserialize_bool(visitor)
        }

        fn deserialize_byte_buf<V>(mut self, visitor: V) -> Result<V::Value, Self::Error>
        where
                V: Visitor<'de> {
            self.inner.deserialize_byte_buf(visitor)
        }

        fn deserialize_bytes<V>(mut self, visitor: V) -> Result<V::Value, Self::Error>
        where
                V: Visitor<'de> {
            self.inner.deserialize_bytes(visitor)
        }

        fn deserialize_char<V>(mut self, visitor: V) -> Result<V::Value, Self::Error>
        where
                V: Visitor<'de> {
            self.inner.deserialize_char(visitor)
        }

        fn deserialize_enum<V>(
                mut self,
                name: &'static str,
                variants: &'static [&'static str],
                visitor: V,
            ) -> Result<V::Value, Self::Error>
        where
                V: Visitor<'de> {
            self.inner.deserialize_enum(name, variants, visitor)
        }

        fn deserialize_f32<V>(mut self, visitor: V) -> Result<V::Value, Self::Error>
        where
                V: Visitor<'de> {
            self.inner.deserialize_f32(visitor)
        }

        fn deserialize_f64<V>(mut self, visitor: V) -> Result<V::Value, Self::Error>
        where
                V: Visitor<'de> {
            self.inner.deserialize_f64(visitor)
        }

        fn deserialize_i16<V>(mut self, visitor: V) -> Result<V::Value, Self::Error>
        where
                V: Visitor<'de> {
            self.inner.deserialize_i16(visitor)
        }

        fn deserialize_i32<V>(mut self, visitor: V) -> Result<V::Value, Self::Error>
        where
                V: Visitor<'de> {
            self.inner.deserialize_i32(visitor)
        }

        fn deserialize_i64<V>(mut self, visitor: V) -> Result<V::Value, Self::Error>
        where
                V: Visitor<'de> {
            self.inner.deserialize_i64(visitor)
        }

        fn deserialize_i8<V>(mut self, visitor: V) -> Result<V::Value, Self::Error>
        where
                V: Visitor<'de> {
            self.inner.deserialize_i8(visitor)
        }

        fn deserialize_identifier<V>(mut self, visitor: V) -> Result<V::Value, Self::Error>
        where
                V: Visitor<'de> {
            self.inner.deserialize_identifier(visitor)
        }

        fn deserialize_ignored_any<V>(mut self, visitor: V) -> Result<V::Value, Self::Error>
        where
                V: Visitor<'de> {
            self.inner.deserialize_ignored_any(visitor)
        }

        fn deserialize_map<V>(mut self, visitor: V) -> Result<V::Value, Self::Error>
        where
                V: Visitor<'de> {
            self.inner.deserialize_map(visitor)
        }

        fn deserialize_newtype_struct<V>(
                mut self,
                name: &'static str,
                visitor: V,
            ) -> Result<V::Value, Self::Error>
        where
                V: Visitor<'de> {
            self.inner.deserialize_newtype_struct(name, visitor)
        }

        fn deserialize_option<V>(mut self, visitor: V) -> Result<V::Value, Self::Error>
        where
                V: Visitor<'de> {
            self.inner.deserialize_option(visitor)
        }

        fn deserialize_seq<V>(mut self, visitor: V) -> Result<V::Value, Self::Error>
        where
                V: Visitor<'de> {
            self.inner.deserialize_seq(visitor)
        }

        fn deserialize_str<V>(mut self, visitor: V) -> Result<V::Value, Self::Error>
        where
                V: Visitor<'de> {
            self.inner.deserialize_str(visitor)
        }

        fn deserialize_string<V>(mut self, visitor: V) -> Result<V::Value, Self::Error>
        where
                V: Visitor<'de> {
            self.inner.deserialize_string(visitor)
        }

        fn deserialize_struct<V>(
                mut self,
                name: &'static str,
                fields: &'static [&'static str],
                visitor: V,
            ) -> Result<V::Value, Self::Error>
        where
                V: Visitor<'de> {
            self.inner.deserialize_struct(name, fields, visitor)
        }

        fn deserialize_tuple<V>(mut self, len: usize, visitor: V) -> Result<V::Value, Self::Error>
        where
                V: Visitor<'de> {
            self.inner.deserialize_tuple(len, visitor)
        }

        fn deserialize_tuple_struct<V>(
                mut self,
                name: &'static str,
                len: usize,
                visitor: V,
            ) -> Result<V::Value, Self::Error>
        where
                V: Visitor<'de> {
            self.inner.deserialize_tuple_struct(name, len, visitor)
        }

        fn deserialize_u16<V>(mut self, visitor: V) -> Result<V::Value, Self::Error>
        where
                V: Visitor<'de> {
            self.inner.deserialize_u16(visitor)
        }

        fn deserialize_u32<V>(mut self, visitor: V) -> Result<V::Value, Self::Error>
        where
                V: Visitor<'de> {
            self.inner.deserialize_u32(visitor)
        }

        fn deserialize_u64<V>(mut self, visitor: V) -> Result<V::Value, Self::Error>
        where
                V: Visitor<'de> {
            self.inner.deserialize_u64(visitor)
        }

        fn deserialize_u8<V>(mut self, visitor: V) -> Result<V::Value, Self::Error>
        where
                V: Visitor<'de> {
            self.inner.deserialize_u8(visitor)
        }

        fn deserialize_unit<V>(mut self, visitor: V) -> Result<V::Value, Self::Error>
        where
                V: Visitor<'de> {
            self.inner.deserialize_unit(visitor)
        }

        fn deserialize_unit_struct<V>(
                mut self,
                name: &'static str,
                visitor: V,
            ) -> Result<V::Value, Self::Error>
        where
                V: Visitor<'de> {
            self.inner.deserialize_unit_struct(name, visitor)
        }
    };

    output.into()
}

/// Export methods in the impl block with #[export_method] attribute. Methods without
/// the attribute will not be affected. This will also generate client stub.
///
/// When using with `#[async_trait]`, place `#[async_trait]` before `#[export_macro]`. 
///
/// Example - Export impl block
///
/// ```rust
/// struct ExampleService { }
///
/// #[export_impl]
/// impl ExampleService {
///     #[export_method]
///     async fn exported_method(&self, args: ()) -> Result<String, String> {
///         Ok("This is an exported method".to_string())
///     }
///
///     async fn not_exported_method(&self, args: ()) -> Result<String, String> {
///         Ok("This method is NOT exported".to_string())
///     }
/// }
/// ```
///
/// Example - use client stub
///
/// ```rust 
/// mod rpc {
///     // service state
///     pub struct Foo { 
///         pub id: i32
///     }       
/// 
///     // service impl
///     #[export_impl] 
///     impl Foo {
///         pub async fn get_id(&self, _: ()) -> Result<i32, String> {
///             Ok(self.id)
///         }
///     }
/// }
/// 
/// use toy_rpc::Client;
/// use rpc::*;
/// 
/// #[async_std::main]
/// async fn main() {
///     let addr = "127.0.0.1:23333";
///     let client = Client::dial(addr).await.unwrap();
/// 
///     // assume the `Foo` service is registered as "foo_service" 
///     // on the server
///     let reply = client.foo("foo_service").get_id(()).await.unwrap();
/// }
/// 
/// ```
#[proc_macro_attribute]
pub fn export_impl(_attr: TokenStream, item: TokenStream) -> TokenStream {
    // parse item
    let input = parse_macro_input!(item as syn::ItemImpl);
    let (handler_impl, names, fn_idents) = transform_impl(input.clone());

    // extract Self type and use it for construct Ident for handler HashMap
    let self_ty = &input.self_ty;
    let ident = match parse_impl_self_ty(self_ty) {
        Ok(i) => i,
        Err(err) => return err.to_compile_error().into(),
    };
    let static_name = format!("{}_{}", SERVICE_PREFIX, ident.to_string().to_uppercase());
    let static_ident = Ident::new(&static_name, ident.span());

    // generate client stub
    let (client_ty, client_impl, stub_trait, stub_impl) = generate_client_stub(&ident, input.clone());

    let lazy = quote! {
        // store the handler functions in a gloabl lazy hashmap
        toy_rpc::lazy_static::lazy_static! {
            pub static ref #static_ident:
                std::collections::HashMap<&'static str, toy_rpc::service::AsyncHandler<#self_ty>>
                = {
                    let mut map: std::collections::HashMap<&'static str, toy_rpc::service::AsyncHandler<#self_ty>>
                        = std::collections::HashMap::new();
                    #(map.insert(#names, #self_ty::#fn_idents);)*;
                    map
                };
        }
    };

    let register_service_impl = generate_register_service_impl(ident);

    let input = remove_export_method_attr(input);
    let client_impl = remove_export_method_attr(client_impl);
    let handler_impl = remove_export_method_attr(handler_impl);

    let output = quote! {
        #input
        #handler_impl
        #client_ty
        #client_impl
        #stub_trait
        #stub_impl
        #lazy
        #register_service_impl
    };
    output.into()
}

/// transform impl block to meet the signature of service function
fn transform_impl(input: syn::ItemImpl) -> (syn::ItemImpl, Vec<String>, Vec<Ident>) {
    let mut names = Vec::new();
    let mut idents = Vec::new();
    let mut output = filter_exported_methods(input);

    output.trait_ = None;
    output
        .items
        .iter_mut()
        // first filter out method
        .filter_map(|item| match item {
            syn::ImplItem::Method(f) => Some(f),
            _ => None,
        })
        .for_each(|f| {
            names.push(f.sig.ident.to_string());
            transform_method(f);
            idents.push(f.sig.ident.clone());
        });

    (output, names, idents)
}

/// transform method to meet the signature of service function
fn transform_method(f: &mut syn::ImplItemMethod) {
    // change function ident
    let ident = f.sig.ident.clone();
    let concat_name = format!("{}_{}", &ident.to_string(), HANDLER_SUFFIX);
    let handler_ident = Ident::new(&concat_name, ident.span());

    // change asyncness
    f.sig.asyncness = None;

    // transform function request type
    if let syn::FnArg::Typed(pt) = f.sig.inputs.last().unwrap() {
        let req_ty = &pt.ty;

        f.block = parse_quote!({
            Box::pin(
                async move {
                    let req: #req_ty = toy_rpc::erased_serde::deserialize(&mut deserializer)
                        .map_err(|e| toy_rpc::error::Error::ParseError(Box::new(e)))?;
                    let res = self.#ident(req).await
                        .map(|r| Box::new(r) as Box<dyn toy_rpc::erased_serde::Serialize + Send + Sync + 'static>)
                        .map_err(|e| toy_rpc::error::Error::ExecutionError(e.to_string()));
                    res
                }
            )
        });

        f.sig.inputs = parse_quote!(
            self: std::sync::Arc<Self>, mut deserializer: Box<dyn toy_rpc::erased_serde::Deserializer<'static> + Send>
        );

        f.sig.output = parse_quote!(
            -> toy_rpc::service::HandlerResultFut
        );
    };

    f.sig.ident = handler_ident;
}

/// remove #[export_method] attribute
fn remove_export_method_attr(mut input: syn::ItemImpl) -> syn::ItemImpl {
    input
        .items
        .iter_mut()
        // first filter out method
        .filter_map(|item| match item {
            syn::ImplItem::Method(f) => Some(f),
            _ => None,
        })
        .for_each(|f| {
            // clear the attributes for now
            f.attrs.retain(|attr| {
                let ident = attr.path.get_ident().unwrap();
                ident != ATTR_EXPORT_METHOD
            })
        });

    input
}

/// Generate client stub for the service impl block
fn generate_client_stub(ident: &Ident, input: syn::ItemImpl) -> (syn::Item, syn::ItemImpl, syn::Item, syn::ItemImpl) {
    let concat_name = format!("{}{}", &ident.to_string(), CLIENT_SUFFIX);
    let client_ident = Ident::new(&concat_name, ident.span());

    let client_struct = parse_quote!(
        pub struct #client_ident<'c> {
            client: &'c toy_rpc::client::Client<toy_rpc::client::Connected>,
            service_name: &'c str,
        }
    );

    let client_impl = client_stub_impl(&client_ident, input);

    let concat_name = format!("{}{}", &ident.to_string(), CLIENT_STUB_SUFFIX);
    let stub_ident = Ident::new(&concat_name, ident.span());
    // let stub_fn_name = Ident::new(&ident.to_string().to_lowercase(), ident.span());
    let stub_fn = parse_stub_fn_name(ident);
    
    let stub_trait = parse_quote!(
        pub trait #stub_ident {
            fn #stub_fn<'c>(&'c self) -> #client_ident;
        }
    );

    let service_name = ident.to_string();
    let stub_impl: syn::ItemImpl = parse_quote!(
        impl #stub_ident for toy_rpc::client::Client<toy_rpc::client::Connected> {
            fn #stub_fn<'c>(&'c self) -> #client_ident {
                #client_ident {
                    client: self,
                    service_name: #service_name,
                }
            }
        }  
    );

    return (client_struct, client_impl, stub_trait, stub_impl)
}

fn client_stub_impl(client_ident: &Ident, input: syn::ItemImpl) -> syn::ItemImpl {
    let mut input = filter_exported_methods(input);
    let mut generated_items: Vec<syn::ImplItem> = Vec::new();
    input.trait_ = None;
    input
        .items
        .iter_mut()
        // first filter out method
        .filter_map(|item| match item {
            syn::ImplItem::Method(f) => Some(f),
            _ => None,
        })
        .for_each(|f| {
            if let Some(gen) = generate_client_stub_method(f) {
                generated_items.push(syn::ImplItem::Method(gen));
            }
        });
    
    let mut output: syn::ItemImpl = parse_quote!(
        impl<'c> #client_ident<'c> {

        }
    );

    output.items = generated_items;
    output
}

fn generate_client_stub_method(f: &mut syn::ImplItemMethod) -> Option<syn::ImplItemMethod> {
    if let syn::FnArg::Typed(pt) = f.sig.inputs.last().unwrap() {
        let fn_ident = &f.sig.ident;
        let req_ty = &pt.ty;
        
        if let syn::ReturnType::Type(_, ret_ty) = f.sig.output.clone() {
            let ok_ty = get_ok_ident_from_type(ret_ty)?;
            return Some(generate_client_stub_method_impl(fn_ident, &req_ty, &ok_ty))
        }
    }

    return None
}   

fn generate_client_stub_method_impl(fn_ident: &Ident, req_ty: &Box<syn::Type>, ok_ty: &GenericArgument) -> syn::ImplItemMethod {
    let method = fn_ident.to_string();
    parse_quote!(
        pub async fn #fn_ident<A>(&'c self, args: A) -> Result<#ok_ty, toy_rpc::error::Error>
        where 
            A: std::borrow::Borrow<#req_ty> + Send + Sync + toy_rpc::serde::Serialize,
        {
            let method = #method;
            let service_method = format!("{}.{}", self.service_name, method);

            self.client.async_call(service_method, args).await
        }
    )
}

fn get_ok_ident_from_type(ty: Box<syn::Type>) -> Option<GenericArgument> {
    let ty = Box::leak(ty);
    let arg = syn::GenericArgument::Type(ty.to_owned());
    return recursively_get_restul_from_generic_arg(&arg)
}

fn recursively_get_restul_from_generic_arg(arg: &GenericArgument) -> Option<GenericArgument> {
    match &arg {
        &syn::GenericArgument::Type(ty) => {
            return recusively_get_result_from_type(&ty);
        },
        &syn::GenericArgument::Binding(binding) => {
            return recusively_get_result_from_type(&binding.ty);
        },
        _ => { None }
    }
}

fn recusively_get_result_from_type(ty: &syn::Type) -> Option<GenericArgument> {
    match ty {
        &syn::Type::Path(ref path) => {
            let ident = &path.path.segments.last()?.ident.to_string()[..];
            match &path.path.segments.last()?.arguments {
                syn::PathArguments::AngleBracketed(angle_bracket) => {
                    if ident == "Result" {
                        return angle_bracket.args.first()
                            .map(|g| g.to_owned())
                    }
                    return recursively_get_restul_from_generic_arg(angle_bracket.args.first()?)
                },
                _ => {
                    return None
                }
            }
        },
        &syn::Type::TraitObject(ref tobj) => {
            if let syn::TypeParamBound::Trait(bound) = tobj.bounds.first()? {
                match &bound.path.segments.last()?.arguments {
                    syn::PathArguments::AngleBracketed(angle_bracket) => {
                        return recursively_get_restul_from_generic_arg(angle_bracket.args.first()?)
                    },
                    _ => {
                        return None
                    }
                }
            }
            None
        }
        _ => {
            None
        }
    }    
}

fn generate_register_service_impl(ident: &Ident) -> impl ToTokens {
    let name = ident.to_string();
    let static_name = format!("{}_{}", SERVICE_PREFIX, &name.to_uppercase());
    let static_ident = syn::Ident::new(&static_name, ident.span());
    let ret = quote! {
        impl toy_rpc::util::RegisterService for #ident {
            fn handlers() -> &'static std::collections::HashMap<&'static str, toy_rpc::service::AsyncHandler<Self>> {
                &*#static_ident
            }

            fn default_name() -> &'static str {
                let name = #name;
                name.as_ref()
            }
        }
    };

    ret
}
struct ServiceExport {
    instance_id: syn::Ident,
    impl_path: syn::Path,
}

impl syn::parse::Parse for ServiceExport {
    fn parse(input: syn::parse::ParseStream) -> Result<Self, syn::Error> {
        let instance_id: syn::Ident = input.parse()?;
        input.parse::<syn::Token![,]>()?;
        let impl_path: syn::Path = input.parse()?;

        Ok(ServiceExport {
            instance_id,
            impl_path,
        })
    }
}

/// Find the exported methods with the provided path
/// 
/// Example 
/// 
/// ```rust
/// struct Foo { }
/// 
/// #[export_impl]
/// impl Foo { 
///     //rpc service impl here
/// }
/// 
/// mod rpc {
///     pub struct Bar { }
/// 
///     #[export_impl]
///     impl Bar {
///         //rpc service impl here
///     }
/// }
/// 
/// use toy_rpc::Server;
/// 
/// fn main() {
///     let foo = Arc::new(Foo {});
///     let bar = Arc::new(rpc::Bar {});
///     
///     let server = Server::builder()
///         .register(foo)
///         .register(bar)
///         .build();
/// }
/// 
/// ```
#[deprecated(
    since = "0.3.0",
    note = "Service can be registered without explicitly using the service macro"
)]
#[proc_macro]
pub fn service(input: TokenStream) -> TokenStream {
    let ServiceExport {
        instance_id,
        impl_path,
    } = parse_macro_input!(input as ServiceExport);

    let last_segment = impl_path.segments.last().unwrap();
    let ident = &last_segment.ident;
    let static_name = format!("{}_{}", SERVICE_PREFIX, &ident.to_string().to_uppercase());
    let static_ident = syn::Ident::new(&static_name, ident.span());
    let mut static_impl_path = impl_path.clone();

    // modify the path
    static_impl_path.segments.last_mut().unwrap().ident = static_ident;

    let output = quote! {
        toy_rpc::service::build_service(#instance_id, &*#static_impl_path)
    };

    output.into()
}

fn parse_impl_self_ty(self_ty: &syn::Type) -> Result<&syn::Ident, syn::Error> {
    match self_ty {
        syn::Type::Path(tp) => Ok(&tp.path.segments[0].ident),
        _ => Err(syn::Error::new_spanned(
            quote! {},
            "Compile Error: Self type",
        )),
    }
}

fn parse_stub_fn_name(ident: &Ident) -> Ident {
    let mut output_fn = String::new();
    for c in ident.to_string().chars() {
        if c.is_uppercase() {
            output_fn.push('_');
            output_fn.push_str(&c.to_lowercase().to_string());
        } else {
            output_fn.push(c);
        }
    }
    output_fn = output_fn.trim_start_matches('_')
        .trim_end_matches('_')
        .into();

    Ident::new(&output_fn, ident.span())
}

fn filter_exported_methods(input: syn::ItemImpl) -> syn::ItemImpl {
    let mut output = input;
    output.items.retain(|item| match item {
        syn::ImplItem::Method(f) => {
            let is_exported = f.attrs.iter().any(|attr| {
                let ident = attr.path.get_ident().unwrap();
                ident == ATTR_EXPORT_METHOD
            });

            is_exported
        }
        _ => false,
    });
    output
}