pub fn impl_py_setter_def(cls: &syn::Type, property_type: PropertyType) -> Result<TokenStream> {
    let python_name = property_type.null_terminated_python_name()?;
    let deprecations = property_type.deprecations();
    let doc = property_type.doc();
    let setter_impl = match property_type {
        PropertyType::Descriptor {
            field: syn::Field {
                ident: Some(ident), ..
            },
            ..
        } => {
            // named struct field
            quote!({ _slf.#ident = _val; })
        }
        PropertyType::Descriptor { field_index, .. } => {
            // tuple struct field
            let index = syn::Index::from(field_index);
            quote!({ _slf.#index = _val; })
        }
        PropertyType::Function { spec, .. } => impl_call_setter(cls, spec)?,
    };

    let slf = match property_type {
        PropertyType::Descriptor { .. } => {
            SelfType::Receiver { mutable: true }.receiver(cls, ExtractErrorMode::Raise)
        }
        PropertyType::Function { self_type, .. } => {
            self_type.receiver(cls, ExtractErrorMode::Raise)
        }
    };
    Ok(quote! {
        ::pyo3::class::PyMethodDefType::Setter({
            #deprecations
            ::pyo3::class::PySetterDef::new(
                #python_name,
                ::pyo3::class::methods::PySetter({
                    unsafe extern "C" fn __wrap(
                        _slf: *mut ::pyo3::ffi::PyObject,
                        _value: *mut ::pyo3::ffi::PyObject,
                        _: *mut ::std::os::raw::c_void
                    ) -> ::std::os::raw::c_int {
                        ::pyo3::callback::handle_panic(|_py| {
                            #slf
                            let _value = _py
                                .from_borrowed_ptr_or_opt(_value)
                                .ok_or_else(|| {
                                    ::pyo3::exceptions::PyAttributeError::new_err("can't delete attribute")
                                })?;
                            let _val = ::pyo3::FromPyObject::extract(_value)?;

                            ::pyo3::callback::convert(_py, #setter_impl)
                        })
                    }
                    __wrap
                }),
                #doc
            )
        })
    })
}
// Used here for PropertyType::Function, used in pyclass for descriptors.
Used here for PropertyType::Function, used in pyclass for descriptors.
Used here for PropertyType :: Function used in pyclass for descriptors .
pub fn impl_py_setter_def(cls: &syn::Type, property_type: PropertyType) -> Result<TokenStream> {
    let python_name = property_type.null_terminated_python_name()?;
    let deprecations = property_type.deprecations();
    let doc = property_type.doc();
    let setter_impl = match property_type {
        PropertyType::Descriptor {
            field: syn::Field {
                ident: Some(ident), ..
            },
            ..
        } => {
            // named struct field
            quote!({ _slf.#ident = _val; })
        }
        PropertyType::Descriptor { field_index, .. } => {
            // tuple struct field
            let index = syn::Index::from(field_index);
            quote!({ _slf.#index = _val; })
        }
        PropertyType::Function { spec, .. } => impl_call_setter(cls, spec)?,
    };
    let slf = match property_type {
        PropertyType::Descriptor { .. } => {
            SelfType::Receiver { mutable: true }.receiver(cls, ExtractErrorMode::Raise)
        }
        PropertyType::Function { self_type, .. } => {
            self_type.receiver(cls, ExtractErrorMode::Raise)
        }
    };
    Ok(quote! {
        ::pyo3::class::PyMethodDefType::Setter({
            #deprecations
            ::pyo3::class::PySetterDef::new(
                #python_name,
                ::pyo3::class::methods::PySetter({
                    unsafe extern "C" fn __wrap(
                        _slf: *mut ::pyo3::ffi::PyObject,
                        _value: *mut ::pyo3::ffi::PyObject,
                        _: *mut ::std::os::raw::c_void
                    ) -> ::std::os::raw::c_int {
                        ::pyo3::callback::handle_panic(|_py| {
                            #slf
                            let _value = _py
                                .from_borrowed_ptr_or_opt(_value)
                                .ok_or_else(|| {
                                    ::pyo3::exceptions::PyAttributeError::new_err("can't delete attribute")
                                })?;
                            let _val = ::pyo3::FromPyObject::extract(_value)?;
                            ::pyo3::callback::convert(_py, #setter_impl)
                        })
                    }
                    __wrap
                }),
                #doc
            )
        })
    })
}
pub fn impl_py_setter_def ( cls : & syn :: Type , property_type : PropertyType ) -> Result < TokenStream > { let python_name = property_type . null_terminated_python_name ( ) ? ; let deprecations = property_type . deprecations ( ) ; let doc = property_type . doc ( ) ; let setter_impl = match property_type { PropertyType :: Descriptor { field : syn :: Field { ident : Some ( ident ) , .. } , .. } => { // named struct field quote ! ( { _slf ident _val } ) } PropertyType :: Descriptor { field_index , .. } => { // tuple struct field let index = syn :: Index :: from ( field_index ) ; quote ! ( { _slf index _val } ) } PropertyType :: Function { spec , .. } => impl_call_setter ( cls , spec ) ? , } ; let slf = match property_type { PropertyType :: Descriptor { .. } => { SelfType :: Receiver { mutable : true } . receiver ( cls , ExtractErrorMode :: Raise ) } PropertyType :: Function { self_type , .. } => { self_type . receiver ( cls , ExtractErrorMode :: Raise ) } } ; Ok ( quote ! { pyo3 class PyMethodDefType Setter ( { deprecations pyo3 class PySetterDef new ( python_name pyo3 class methods PySetter ( { unsafe extern " " fn __wrap ( _slf mut pyo3 ffi PyObject _value mut pyo3 ffi PyObject mut std os raw c_void ) std os raw c_int { pyo3 callback handle_panic ( py { slf let _value _py from_borrowed_ptr_or_opt ( _value ) ok_or_else ( { pyo3 exceptions PyAttributeError new_err ( " " ) } ) let _val pyo3 FromPyObject extract ( _value ) pyo3 callback convert ( _py setter_impl ) } ) } __wrap } ) doc ) } ) } ) }
Used here for PropertyType::Function, used in pyclass for descriptors.
Used here for PropertyType :: Function used in pyclass for descriptors .
cls
&syn::Type
property_type
PropertyType