From eccc2c56937b6aa7cf0f84265147c704a660fe8b Mon Sep 17 00:00:00 2001 From: Mike Foster Date: Sun, 14 Apr 2024 13:38:26 +0000 Subject: [PATCH] convert from ItemFn to Pyo3TestCase using From/Into --- pyo3-testing/src/lib.rs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/pyo3-testing/src/lib.rs b/pyo3-testing/src/lib.rs index 7c3558ef444..3c0bd5954fc 100644 --- a/pyo3-testing/src/lib.rs +++ b/pyo3-testing/src/lib.rs @@ -124,18 +124,23 @@ struct Pyo3TestCase { statements: Vec, } +impl From for Pyo3TestCase { + fn from(testcase: ItemFn) -> Pyo3TestCase { + Pyo3TestCase { + imports: testcase + .attrs + .into_iter() + .map(|attr| { parsepyo3import(&attr) }.unwrap()) + .collect(), + signature: testcase.sig, + statements: testcase.block.stmts, + } + } +} + #[allow(dead_code)] // Not yet fully implemented fn impl_pyo3test(_attr: TokenStream2, input: TokenStream2) -> TokenStream2 { - let input: ItemFn = parse2(input).unwrap(); - let testcase = Pyo3TestCase { - imports: input - .attrs - .into_iter() - .map(|attr| { parsepyo3import(&attr) }.unwrap()) - .collect(), - signature: input.sig, - statements: input.block.stmts, - }; + let testcase: Pyo3TestCase = parse2::(input).unwrap().into(); wrap_testcase(testcase) }