use crate::TokenStream; use syn::*; pub type Result> = std::result::Result; #[allow(unused)] pub fn return_error(error: &str) -> crate::TokenStream { format!(r#"compile_error!("{}")"#, error).parse().expect("Failed to parse macro") } const STUBBED_BODY: &str = "{ unimplemented!(\"This is a stub function generated by onlytypes.\") }"; pub fn stub_func_body<'a>(b: &'a Block) -> Result<(&'a Block, Block)> { let token_stream: TokenStream = STUBBED_BODY.parse().expect("Failed to parse stubbed body"); let stubbed = parse2::(token_stream).expect("Failed to parse stubbed body"); Ok((b, stubbed)) } pub struct SomeFunction { pub attrs: Vec, pub vis: Visibility, pub defaultness: Option, pub sig: Signature, pub block: Block, } impl From for SomeFunction { fn from(f: ItemFn) -> Self { Self { attrs: f.attrs, vis: f.vis, defaultness: None, sig: f.sig, block: *f.block, } } } impl From for SomeFunction { fn from(f: ImplItemFn) -> Self { Self { attrs: f.attrs, vis: f.vis, defaultness: f.defaultness, sig: f.sig, block: f.block, } } } impl From<&ItemFn> for SomeFunction { fn from(f: &ItemFn) -> Self { Self::from(f.clone()) } } impl From<&ImplItemFn> for SomeFunction { fn from(f: &ImplItemFn) -> Self { Self::from(f.clone()) } }