pub fn pymodule_impl(
    fnname: &Ident,
    options: PyModuleOptions,
    doc: PythonDoc,
    visibility: &Visibility,
) -> TokenStream {
    let name = options.name.unwrap_or_else(|| fnname.unraw());
    let krate = get_pyo3_crate(&options.krate);
    let cb_name = Ident::new(&format!("PyInit_{}", name), Span::call_site());

    let module_def_name = module_def_ident(fnname);

    quote! {
        #[no_mangle]
        #[allow(non_snake_case)]
        /// This autogenerated function is called by the python interpreter when importing
        /// the module.
        pub unsafe extern "C" fn #cb_name() -> *mut #krate::ffi::PyObject {
            use #krate::{self as _pyo3, IntoPyPointer};
            _pyo3::callback::handle_panic(|_py| ::std::result::Result::Ok(#module_def_name.make_module(_py)?.into_ptr()))
        }

        #[doc(hidden)]
        #visibility static #module_def_name: #krate::impl_::pymodule::ModuleDef = unsafe {
            #krate::impl_::pymodule::ModuleDef::new(concat!(stringify!(#name), "\0"), #doc, #krate::impl_::pymodule::ModuleInitializer(#fnname))
        };
    }
}
/// Generates the function that is called by the python interpreter to initialize the native
/// module
Generates the function that is called by the python interpreter to initialize the native
module
Generates the function that is called by the python interpreter to initialize the native module
pub fn pymodule_impl(
    fnname: &Ident,
    options: PyModuleOptions,
    doc: PythonDoc,
    visibility: &Visibility,
) -> TokenStream {
    let name = options.name.unwrap_or_else(|| fnname.unraw());
    let krate = get_pyo3_crate(&options.krate);
    let cb_name = Ident::new(&format!("PyInit_{}", name), Span::call_site());
    let module_def_name = module_def_ident(fnname);
    quote! {
        #[no_mangle]
        #[allow(non_snake_case)]
        /// This autogenerated function is called by the python interpreter when importing
        /// the module.
        pub unsafe extern "C" fn #cb_name() -> *mut #krate::ffi::PyObject {
            use #krate::{self as _pyo3, IntoPyPointer};
            _pyo3::callback::handle_panic(|_py| ::std::result::Result::Ok(#module_def_name.make_module(_py)?.into_ptr()))
        }
        #[doc(hidden)]
        #visibility static #module_def_name: #krate::impl_::pymodule::ModuleDef = unsafe {
            #krate::impl_::pymodule::ModuleDef::new(concat!(stringify!(#name), "\0"), #doc, #krate::impl_::pymodule::ModuleInitializer(#fnname))
        };
    }
}
pub fn pymodule_impl ( fnname : & Ident , options : PyModuleOptions , doc : PythonDoc , visibility : & Visibility , ) -> TokenStream { let name = options . name . unwrap_or_else ( | | fnname . unraw ( ) ) ; let krate = get_pyo3_crate ( & options . krate ) ; let cb_name = Ident :: new ( & format ! ( " " name ) , Span :: call_site ( ) ) ; let module_def_name = module_def_ident ( fnname ) ; quote ! { [ no_mangle ] [ allow ( non_snake_case ) ] /// This autogenerated function is called by the python interpreter when importing /// the module. pub unsafe extern " " fn cb_name ( ) mut krate ffi PyObject { use krate { self as _pyo3 IntoPyPointer } _pyo3 callback handle_panic ( py std result Result Ok ( module_def_name make_module ( _py ) into_ptr ( ) ) ) } [ doc ( hidden ) ] visibility static module_def_name krate impl_ pymodule ModuleDef unsafe { krate impl_ pymodule ModuleDef new ( concat ( stringify ( name ) " \0 " ) doc krate impl_ pymodule ModuleInitializer ( fnname ) ) } } }
Generates the function that is called by the python interpreter to initialize the native
module
Generates the function that is called by the python interpreter to initialize the native module
fnname
&Ident
options
PyModuleOptions
doc
PythonDoc
visibility
&Visibility
fnname
&Ident
options
PyModuleOptions
doc
PythonDoc
visibility
&Visibility