-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitem_fn.rs
38 lines (31 loc) · 1.16 KB
/
item_fn.rs
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
use proc_macro2::Ident;
use syn::{Error, ImplItemFn, Result};
use crate::analyze::utils::TypescriptArg;
use super::utils::{ApiMethodArgs, TypescriptType};
#[derive(Debug)]
pub struct ImplItemFnModel {
pub original_method_ident: Ident,
pub api_method_args: ApiMethodArgs,
pub typescript_arguments: Vec<TypescriptArg>,
pub typescript_return_type: TypescriptType,
}
impl TryFrom<&ImplItemFn> for ImplItemFnModel {
type Error = Error;
fn try_from(method: &ImplItemFn) -> std::prelude::v1::Result<Self, Self::Error> {
let method_name = &method.sig.ident;
let method_inputs = &method.sig.inputs;
let method_output = &method.sig.output;
let api_method_args = ApiMethodArgs::try_from(method_inputs)?;
let typescript_arguments = api_method_args
.api_args
.iter()
.map(TypescriptArg::try_from)
.collect::<Result<Vec<TypescriptArg>>>()?;
Ok(ImplItemFnModel {
original_method_ident: method_name.clone(),
api_method_args,
typescript_arguments,
typescript_return_type: TypescriptType::try_from(method_output)?,
})
}
}