1 | use crate::utils::Ctx; |
2 | use proc_macro2::TokenStream; |
3 | use quote::{quote, quote_spanned}; |
4 | |
5 | pub(crate) fn some_wrap(obj: TokenStream, ctx: &Ctx) -> TokenStream { |
6 | let Ctx { pyo3_path: &PyO3CratePath, .. } = ctx; |
7 | quote! { |
8 | #pyo3_path::impl_::wrap::SomeWrap::wrap(#obj) |
9 | } |
10 | } |
11 | |
12 | pub(crate) fn ok_wrap(obj: TokenStream, ctx: &Ctx) -> TokenStream { |
13 | let Ctx { |
14 | pyo3_path: &PyO3CratePath, |
15 | output_span: &Span, |
16 | } = ctx; |
17 | let pyo3_path: TokenStream = pyo3_path.to_tokens_spanned(*output_span); |
18 | quote_spanned! { *output_span => { |
19 | let obj = #obj; |
20 | #[allow(clippy::useless_conversion)] |
21 | #pyo3_path::impl_::wrap::converter(&obj).wrap(obj).map_err(::core::convert::Into::<#pyo3_path::PyErr>::into) |
22 | }} |
23 | } |
24 | |
25 | pub(crate) fn map_result_into_ptr(result: TokenStream, ctx: &Ctx) -> TokenStream { |
26 | let Ctx { |
27 | pyo3_path: &PyO3CratePath, |
28 | output_span: &Span, |
29 | } = ctx; |
30 | let pyo3_path: TokenStream = pyo3_path.to_tokens_spanned(*output_span); |
31 | let py: Ident = syn::Ident::new(string:"py" , proc_macro2::Span::call_site()); |
32 | quote_spanned! { *output_span => { |
33 | let result = #result; |
34 | #pyo3_path::impl_::wrap::converter(&result).map_into_ptr(#py, result) |
35 | }} |
36 | } |
37 | |