pyo3_macros_backend/
quotes.rs

1use crate::utils::Ctx;
2use proc_macro2::TokenStream;
3use quote::{quote, quote_spanned};
4
5pub(crate) fn some_wrap(obj: TokenStream, ctx: &Ctx) -> TokenStream {
6    let Ctx { pyo3_path, .. } = ctx;
7    quote! {
8        #pyo3_path::impl_::wrap::SomeWrap::wrap(#obj)
9    }
10}
11
12pub(crate) fn ok_wrap(obj: TokenStream, ctx: &Ctx) -> TokenStream {
13    let Ctx {
14        pyo3_path,
15        output_span,
16    } = ctx;
17    let pyo3_path = 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
25pub(crate) fn map_result_into_ptr(result: TokenStream, ctx: &Ctx) -> TokenStream {
26    let Ctx {
27        pyo3_path,
28        output_span,
29    } = ctx;
30    let pyo3_path = pyo3_path.to_tokens_spanned(*output_span);
31    let py = syn::Ident::new("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}
⚠️ Internal Docs ⚠️ Not Public API 👉 Official Docs Here