mod command_enum; mod lua_wrapper; pub use command_enum::command_enum; pub use lua_wrapper::lua_wrapper; use syn::{ReturnType, Type, TypeBareFn}; use crate::command_enum_parsing::FunctionDeclaration; pub fn get_bare_fn_input_type(function: &TypeBareFn) -> Option { if function.inputs.len() == 1 { Some( function .inputs .first() .expect("Only one element exists, we checked the length above") .ty .clone(), ) } else if function.inputs.len() == 0 { // No inputs, so we can't return a type None } else { unreachable!( "The Function can only take one or zero arguments. Use a tuple `(arg1, arg2)` if you want more" ); } } pub fn get_input_type_of_bare_fn_field(field: &FunctionDeclaration) -> Option { match &field.ty { syn::Type::BareFn(function) => get_bare_fn_input_type(&function), _ => unimplemented!( "Please specify the type as a bare fn type. That is: `fn() -> `" ), } } pub fn get_return_type_of_bare_fn_field(field: &FunctionDeclaration) -> Option { match &field.ty { syn::Type::BareFn(function) => get_bare_fn_return_type(&function), _ => unimplemented!( "Please specify the type as a bare fn type. That is: `fn() -> `" ), } } pub fn get_bare_fn_return_type(function: &TypeBareFn) -> Option { let return_path: &ReturnType = &function.output; match return_path { ReturnType::Default => None, ReturnType::Type(_, return_type) => Some(*return_type.to_owned()), } }