Merge pull request #615 from PyO3/fix-specialization

Fix broken specialized implementations with Rust 1.40
This commit is contained in:
Yuji Kanagawa 2019-10-08 01:39:07 +09:00 committed by GitHub
commit d602b65347
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 829 additions and 328 deletions

View File

@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Fixed ### Fixed
* Make sure the right Python interpreter is used in OSX builds. [#604](https://github.com/PyO3/pyo3/pull/604) * Make sure the right Python interpreter is used in OSX builds. [#604](https://github.com/PyO3/pyo3/pull/604)
* Patch specialization being broken by Rust 1.40 [#614](https://github.com/PyO3/pyo3/issues/614)
## [0.8.0] - 2018-09-05 ## [0.8.0] - 2018-09-05

View File

@ -38,7 +38,7 @@ pub fn gen_py_method(
return Err(syn::Error::new_spanned( return Err(syn::Error::new_spanned(
spec.args[0].ty, spec.args[0].ty,
"Getter function can only have one argument of type pyo3::Python!", "Getter function can only have one argument of type pyo3::Python!",
)) ));
} }
}; };
impl_py_getter_def(name, doc, getter, &impl_wrap_getter(cls, name, takes_py)) impl_py_getter_def(name, doc, getter, &impl_wrap_getter(cls, name, takes_py))
@ -60,10 +60,10 @@ fn check_generic(name: &syn::Ident, sig: &syn::Signature) -> syn::Result<()> {
match param { match param {
syn::GenericParam::Lifetime(_) => {} syn::GenericParam::Lifetime(_) => {}
syn::GenericParam::Type(_) => { syn::GenericParam::Type(_) => {
return Err(syn::Error::new_spanned(param, err_msg("type"))) return Err(syn::Error::new_spanned(param, err_msg("type")));
} }
syn::GenericParam::Const(_) => { syn::GenericParam::Const(_) => {
return Err(syn::Error::new_spanned(param, err_msg("const"))) return Err(syn::Error::new_spanned(param, err_msg("const")));
} }
} }
} }

View File

@ -152,17 +152,21 @@ pub trait PyObjectRichcmpProtocol<'p>: PyObjectProtocol<'p> {
#[doc(hidden)] #[doc(hidden)]
pub trait PyObjectProtocolImpl { pub trait PyObjectProtocolImpl {
fn methods() -> Vec<PyMethodDef> { fn methods() -> Vec<PyMethodDef>;
fn tp_as_object(_type_object: &mut ffi::PyTypeObject);
fn nb_bool_fn() -> Option<ffi::inquiry>;
}
impl<T> PyObjectProtocolImpl for T {
default fn methods() -> Vec<PyMethodDef> {
Vec::new() Vec::new()
} }
fn tp_as_object(_type_object: &mut ffi::PyTypeObject) {} default fn tp_as_object(_type_object: &mut ffi::PyTypeObject) {}
fn nb_bool_fn() -> Option<ffi::inquiry> { default fn nb_bool_fn() -> Option<ffi::inquiry> {
None None
} }
} }
impl<T> PyObjectProtocolImpl for T {}
impl<'p, T> PyObjectProtocolImpl for T impl<'p, T> PyObjectProtocolImpl for T
where where
T: PyObjectProtocol<'p>, T: PyObjectProtocol<'p>,
@ -195,13 +199,18 @@ where
} }
trait GetAttrProtocolImpl { trait GetAttrProtocolImpl {
fn tp_getattro() -> Option<ffi::binaryfunc> { fn tp_getattro() -> Option<ffi::binaryfunc>;
}
impl<'p, T> GetAttrProtocolImpl for T
where
T: PyObjectProtocol<'p>,
{
default fn tp_getattro() -> Option<ffi::binaryfunc> {
None None
} }
} }
impl<'p, T> GetAttrProtocolImpl for T where T: PyObjectProtocol<'p> {}
impl<T> GetAttrProtocolImpl for T impl<T> GetAttrProtocolImpl for T
where where
T: for<'p> PyObjectGetAttrProtocol<'p>, T: for<'p> PyObjectGetAttrProtocol<'p>,
@ -268,13 +277,15 @@ mod tp_setattro_impl {
} }
trait SetAttr { trait SetAttr {
fn set_attr() -> Option<ffi::setattrofunc> { fn set_attr() -> Option<ffi::setattrofunc>;
}
impl<'p, T: PyObjectProtocol<'p>> SetAttr for T {
default fn set_attr() -> Option<ffi::setattrofunc> {
None None
} }
} }
impl<'p, T: PyObjectProtocol<'p>> SetAttr for T {}
impl<T> SetAttr for T impl<T> SetAttr for T
where where
T: for<'p> PyObjectSetAttrProtocol<'p>, T: for<'p> PyObjectSetAttrProtocol<'p>,
@ -285,13 +296,18 @@ mod tp_setattro_impl {
} }
trait DelAttr { trait DelAttr {
fn del_attr() -> Option<ffi::setattrofunc> { fn del_attr() -> Option<ffi::setattrofunc>;
}
impl<'p, T> DelAttr for T
where
T: PyObjectProtocol<'p>,
{
default fn del_attr() -> Option<ffi::setattrofunc> {
None None
} }
} }
impl<'p, T> DelAttr for T where T: PyObjectProtocol<'p> {}
impl<T> DelAttr for T impl<T> DelAttr for T
where where
T: for<'p> PyObjectDelAttrProtocol<'p>, T: for<'p> PyObjectDelAttrProtocol<'p>,
@ -302,13 +318,18 @@ mod tp_setattro_impl {
} }
trait SetDelAttr { trait SetDelAttr {
fn set_del_attr() -> Option<ffi::setattrofunc> { fn set_del_attr() -> Option<ffi::setattrofunc>;
}
impl<'p, T> SetDelAttr for T
where
T: PyObjectProtocol<'p>,
{
default fn set_del_attr() -> Option<ffi::setattrofunc> {
None None
} }
} }
impl<'p, T> SetDelAttr for T where T: PyObjectProtocol<'p> {}
impl<T> SetDelAttr for T impl<T> SetDelAttr for T
where where
T: for<'p> PyObjectSetAttrProtocol<'p> + for<'p> PyObjectDelAttrProtocol<'p>, T: for<'p> PyObjectSetAttrProtocol<'p> + for<'p> PyObjectDelAttrProtocol<'p>,
@ -326,11 +347,16 @@ mod tp_setattro_impl {
} }
trait StrProtocolImpl { trait StrProtocolImpl {
fn tp_str() -> Option<ffi::unaryfunc> { fn tp_str() -> Option<ffi::unaryfunc>;
}
impl<'p, T> StrProtocolImpl for T
where
T: PyObjectProtocol<'p>,
{
default fn tp_str() -> Option<ffi::unaryfunc> {
None None
} }
} }
impl<'p, T> StrProtocolImpl for T where T: PyObjectProtocol<'p> {}
impl<T> StrProtocolImpl for T impl<T> StrProtocolImpl for T
where where
T: for<'p> PyObjectStrProtocol<'p>, T: for<'p> PyObjectStrProtocol<'p>,
@ -346,11 +372,16 @@ where
} }
trait ReprProtocolImpl { trait ReprProtocolImpl {
fn tp_repr() -> Option<ffi::unaryfunc> { fn tp_repr() -> Option<ffi::unaryfunc>;
}
impl<'p, T> ReprProtocolImpl for T
where
T: PyObjectProtocol<'p>,
{
default fn tp_repr() -> Option<ffi::unaryfunc> {
None None
} }
} }
impl<'p, T> ReprProtocolImpl for T where T: PyObjectProtocol<'p> {}
impl<T> ReprProtocolImpl for T impl<T> ReprProtocolImpl for T
where where
T: for<'p> PyObjectReprProtocol<'p>, T: for<'p> PyObjectReprProtocol<'p>,
@ -367,34 +398,54 @@ where
#[doc(hidden)] #[doc(hidden)]
pub trait FormatProtocolImpl { pub trait FormatProtocolImpl {
fn __format__() -> Option<PyMethodDef> { fn __format__() -> Option<PyMethodDef>;
}
impl<'p, T> FormatProtocolImpl for T
where
T: PyObjectProtocol<'p>,
{
default fn __format__() -> Option<PyMethodDef> {
None None
} }
} }
impl<'p, T> FormatProtocolImpl for T where T: PyObjectProtocol<'p> {}
#[doc(hidden)] #[doc(hidden)]
pub trait BytesProtocolImpl { pub trait BytesProtocolImpl {
fn __bytes__() -> Option<PyMethodDef> { fn __bytes__() -> Option<PyMethodDef>;
}
impl<'p, T> BytesProtocolImpl for T
where
T: PyObjectProtocol<'p>,
{
default fn __bytes__() -> Option<PyMethodDef> {
None None
} }
} }
impl<'p, T> BytesProtocolImpl for T where T: PyObjectProtocol<'p> {}
#[doc(hidden)] #[doc(hidden)]
pub trait UnicodeProtocolImpl { pub trait UnicodeProtocolImpl {
fn __unicode__() -> Option<PyMethodDef> { fn __unicode__() -> Option<PyMethodDef>;
}
impl<'p, T> UnicodeProtocolImpl for T
where
T: PyObjectProtocol<'p>,
{
default fn __unicode__() -> Option<PyMethodDef> {
None None
} }
} }
impl<'p, T> UnicodeProtocolImpl for T where T: PyObjectProtocol<'p> {}
trait HashProtocolImpl { trait HashProtocolImpl {
fn tp_hash() -> Option<ffi::hashfunc> { fn tp_hash() -> Option<ffi::hashfunc>;
}
impl<'p, T> HashProtocolImpl for T
where
T: PyObjectProtocol<'p>,
{
default fn tp_hash() -> Option<ffi::hashfunc> {
None None
} }
} }
impl<'p, T> HashProtocolImpl for T where T: PyObjectProtocol<'p> {}
impl<T> HashProtocolImpl for T impl<T> HashProtocolImpl for T
where where
T: for<'p> PyObjectHashProtocol<'p>, T: for<'p> PyObjectHashProtocol<'p>,
@ -411,11 +462,16 @@ where
} }
trait BoolProtocolImpl { trait BoolProtocolImpl {
fn nb_bool() -> Option<ffi::inquiry> { fn nb_bool() -> Option<ffi::inquiry>;
}
impl<'p, T> BoolProtocolImpl for T
where
T: PyObjectProtocol<'p>,
{
default fn nb_bool() -> Option<ffi::inquiry> {
None None
} }
} }
impl<'p, T> BoolProtocolImpl for T where T: PyObjectProtocol<'p> {}
impl<T> BoolProtocolImpl for T impl<T> BoolProtocolImpl for T
where where
T: for<'p> PyObjectBoolProtocol<'p>, T: for<'p> PyObjectBoolProtocol<'p>,
@ -432,11 +488,16 @@ where
} }
trait RichcmpProtocolImpl { trait RichcmpProtocolImpl {
fn tp_richcompare() -> Option<ffi::richcmpfunc> { fn tp_richcompare() -> Option<ffi::richcmpfunc>;
}
impl<'p, T> RichcmpProtocolImpl for T
where
T: PyObjectProtocol<'p>,
{
default fn tp_richcompare() -> Option<ffi::richcmpfunc> {
None None
} }
} }
impl<'p, T> RichcmpProtocolImpl for T where T: PyObjectProtocol<'p> {}
impl<T> RichcmpProtocolImpl for T impl<T> RichcmpProtocolImpl for T
where where
T: for<'p> PyObjectRichcmpProtocol<'p>, T: for<'p> PyObjectRichcmpProtocol<'p>,

View File

@ -41,13 +41,15 @@ pub trait PyBufferReleaseBufferProtocol<'p>: PyBufferProtocol<'p> {
#[doc(hidden)] #[doc(hidden)]
pub trait PyBufferProtocolImpl { pub trait PyBufferProtocolImpl {
fn tp_as_buffer() -> Option<ffi::PyBufferProcs> { fn tp_as_buffer() -> Option<ffi::PyBufferProcs>;
}
impl<T> PyBufferProtocolImpl for T {
default fn tp_as_buffer() -> Option<ffi::PyBufferProcs> {
None None
} }
} }
impl<T> PyBufferProtocolImpl for T {}
impl<'p, T> PyBufferProtocolImpl for T impl<'p, T> PyBufferProtocolImpl for T
where where
T: PyBufferProtocol<'p>, T: PyBufferProtocol<'p>,
@ -64,13 +66,18 @@ where
} }
trait PyBufferGetBufferProtocolImpl { trait PyBufferGetBufferProtocolImpl {
fn cb_bf_getbuffer() -> Option<ffi::getbufferproc> { fn cb_bf_getbuffer() -> Option<ffi::getbufferproc>;
}
impl<'p, T> PyBufferGetBufferProtocolImpl for T
where
T: PyBufferProtocol<'p>,
{
default fn cb_bf_getbuffer() -> Option<ffi::getbufferproc> {
None None
} }
} }
impl<'p, T> PyBufferGetBufferProtocolImpl for T where T: PyBufferProtocol<'p> {}
impl<T> PyBufferGetBufferProtocolImpl for T impl<T> PyBufferGetBufferProtocolImpl for T
where where
T: for<'p> PyBufferGetBufferProtocol<'p>, T: for<'p> PyBufferGetBufferProtocol<'p>,

View File

@ -47,13 +47,15 @@ pub trait PyContextExitProtocol<'p>: PyContextProtocol<'p> {
#[doc(hidden)] #[doc(hidden)]
pub trait PyContextProtocolImpl { pub trait PyContextProtocolImpl {
fn methods() -> Vec<PyMethodDef> { fn methods() -> Vec<PyMethodDef>;
}
impl<T> PyContextProtocolImpl for T {
default fn methods() -> Vec<PyMethodDef> {
Vec::new() Vec::new()
} }
} }
impl<T> PyContextProtocolImpl for T {}
impl<'p, T> PyContextProtocolImpl for T impl<'p, T> PyContextProtocolImpl for T
where where
T: PyContextProtocol<'p>, T: PyContextProtocol<'p>,
@ -75,18 +77,28 @@ where
#[doc(hidden)] #[doc(hidden)]
pub trait PyContextEnterProtocolImpl { pub trait PyContextEnterProtocolImpl {
fn __enter__() -> Option<PyMethodDef> { fn __enter__() -> Option<PyMethodDef>;
}
impl<'p, T> PyContextEnterProtocolImpl for T
where
T: PyContextProtocol<'p>,
{
default fn __enter__() -> Option<PyMethodDef> {
None None
} }
} }
impl<'p, T> PyContextEnterProtocolImpl for T where T: PyContextProtocol<'p> {}
#[doc(hidden)] #[doc(hidden)]
pub trait PyContextExitProtocolImpl { pub trait PyContextExitProtocolImpl {
fn __exit__() -> Option<PyMethodDef> { fn __exit__() -> Option<PyMethodDef>;
}
impl<'p, T> PyContextExitProtocolImpl for T
where
T: PyContextProtocol<'p>,
{
default fn __exit__() -> Option<PyMethodDef> {
None None
} }
} }
impl<'p, T> PyContextExitProtocolImpl for T where T: PyContextProtocol<'p> {}

View File

@ -70,11 +70,16 @@ pub trait PyDescrSetNameProtocol<'p>: PyDescrProtocol<'p> {
} }
trait PyDescrGetProtocolImpl { trait PyDescrGetProtocolImpl {
fn tp_descr_get() -> Option<ffi::descrgetfunc> { fn tp_descr_get() -> Option<ffi::descrgetfunc>;
}
impl<'p, T> PyDescrGetProtocolImpl for T
where
T: PyDescrProtocol<'p>,
{
default fn tp_descr_get() -> Option<ffi::descrgetfunc> {
None None
} }
} }
impl<'p, T> PyDescrGetProtocolImpl for T where T: PyDescrProtocol<'p> {}
impl<T> PyDescrGetProtocolImpl for T impl<T> PyDescrGetProtocolImpl for T
where where
@ -91,11 +96,16 @@ where
} }
trait PyDescrSetProtocolImpl { trait PyDescrSetProtocolImpl {
fn tp_descr_set() -> Option<ffi::descrsetfunc> { fn tp_descr_set() -> Option<ffi::descrsetfunc>;
}
impl<'p, T> PyDescrSetProtocolImpl for T
where
T: PyDescrProtocol<'p>,
{
default fn tp_descr_set() -> Option<ffi::descrsetfunc> {
None None
} }
} }
impl<'p, T> PyDescrSetProtocolImpl for T where T: PyDescrProtocol<'p> {}
impl<T> PyDescrSetProtocolImpl for T impl<T> PyDescrSetProtocolImpl for T
where where
T: for<'p> PyDescrSetProtocol<'p>, T: for<'p> PyDescrSetProtocol<'p>,
@ -127,13 +137,16 @@ impl<'p, T> PyDescrSetNameProtocolImpl for T where T: PyDescrProtocol<'p> {}
#[doc(hidden)] #[doc(hidden)]
pub trait PyDescrProtocolImpl { pub trait PyDescrProtocolImpl {
fn methods() -> Vec<PyMethodDef> { fn methods() -> Vec<PyMethodDef>;
Vec::new() fn tp_as_descr(_type_object: &mut ffi::PyTypeObject);
}
fn tp_as_descr(_type_object: &mut ffi::PyTypeObject) {}
} }
impl<T> PyDescrProtocolImpl for T {} impl<T> PyDescrProtocolImpl for T {
default fn methods() -> Vec<PyMethodDef> {
Vec::new()
}
default fn tp_as_descr(_type_object: &mut ffi::PyTypeObject) {}
}
impl<'p, T> PyDescrProtocolImpl for T impl<'p, T> PyDescrProtocolImpl for T
where where

View File

@ -23,10 +23,12 @@ pub trait PyGCClearProtocol<'p>: PyGCProtocol<'p> {}
#[doc(hidden)] #[doc(hidden)]
pub trait PyGCProtocolImpl { pub trait PyGCProtocolImpl {
fn update_type_object(_type_object: &mut ffi::PyTypeObject) {} fn update_type_object(_type_object: &mut ffi::PyTypeObject);
} }
impl<'p, T> PyGCProtocolImpl for T {} impl<'p, T> PyGCProtocolImpl for T {
default fn update_type_object(_type_object: &mut ffi::PyTypeObject) {}
}
impl<'p, T> PyGCProtocolImpl for T impl<'p, T> PyGCProtocolImpl for T
where where
@ -63,13 +65,18 @@ impl<'p> PyVisit<'p> {
} }
trait PyGCTraverseProtocolImpl { trait PyGCTraverseProtocolImpl {
fn tp_traverse() -> Option<ffi::traverseproc> { fn tp_traverse() -> Option<ffi::traverseproc>;
}
impl<'p, T> PyGCTraverseProtocolImpl for T
where
T: PyGCProtocol<'p>,
{
default fn tp_traverse() -> Option<ffi::traverseproc> {
None None
} }
} }
impl<'p, T> PyGCTraverseProtocolImpl for T where T: PyGCProtocol<'p> {}
#[doc(hidden)] #[doc(hidden)]
impl<T> PyGCTraverseProtocolImpl for T impl<T> PyGCTraverseProtocolImpl for T
where where
@ -105,13 +112,18 @@ where
} }
trait PyGCClearProtocolImpl { trait PyGCClearProtocolImpl {
fn tp_clear() -> Option<ffi::inquiry> { fn tp_clear() -> Option<ffi::inquiry>;
}
impl<'p, T> PyGCClearProtocolImpl for T
where
T: PyGCProtocol<'p>,
{
default fn tp_clear() -> Option<ffi::inquiry> {
None None
} }
} }
impl<'p, T> PyGCClearProtocolImpl for T where T: PyGCProtocol<'p> {}
impl<T> PyGCClearProtocolImpl for T impl<T> PyGCClearProtocolImpl for T
where where
T: for<'p> PyGCClearProtocol<'p>, T: for<'p> PyGCClearProtocol<'p>,

View File

@ -44,10 +44,12 @@ pub trait PyIterNextProtocol<'p>: PyIterProtocol<'p> {
#[doc(hidden)] #[doc(hidden)]
pub trait PyIterProtocolImpl { pub trait PyIterProtocolImpl {
fn tp_as_iter(_typeob: &mut ffi::PyTypeObject) {} fn tp_as_iter(_typeob: &mut ffi::PyTypeObject);
} }
impl<T> PyIterProtocolImpl for T {} impl<T> PyIterProtocolImpl for T {
default fn tp_as_iter(_typeob: &mut ffi::PyTypeObject) {}
}
impl<'p, T> PyIterProtocolImpl for T impl<'p, T> PyIterProtocolImpl for T
where where
@ -61,13 +63,18 @@ where
} }
trait PyIterIterProtocolImpl { trait PyIterIterProtocolImpl {
fn tp_iter() -> Option<ffi::getiterfunc> { fn tp_iter() -> Option<ffi::getiterfunc>;
}
impl<'p, T> PyIterIterProtocolImpl for T
where
T: PyIterProtocol<'p>,
{
default fn tp_iter() -> Option<ffi::getiterfunc> {
None None
} }
} }
impl<'p, T> PyIterIterProtocolImpl for T where T: PyIterProtocol<'p> {}
impl<T> PyIterIterProtocolImpl for T impl<T> PyIterIterProtocolImpl for T
where where
T: for<'p> PyIterIterProtocol<'p>, T: for<'p> PyIterIterProtocol<'p>,
@ -84,13 +91,18 @@ where
} }
trait PyIterNextProtocolImpl { trait PyIterNextProtocolImpl {
fn tp_iternext() -> Option<ffi::iternextfunc> { fn tp_iternext() -> Option<ffi::iternextfunc>;
}
impl<'p, T> PyIterNextProtocolImpl for T
where
T: PyIterProtocol<'p>,
{
default fn tp_iternext() -> Option<ffi::iternextfunc> {
None None
} }
} }
impl<'p, T> PyIterNextProtocolImpl for T where T: PyIterProtocol<'p> {}
impl<T> PyIterNextProtocolImpl for T impl<T> PyIterNextProtocolImpl for T
where where
T: for<'p> PyIterNextProtocol<'p>, T: for<'p> PyIterNextProtocol<'p>,

View File

@ -106,16 +106,19 @@ pub trait PyMappingReversedProtocol<'p>: PyMappingProtocol<'p> {
#[doc(hidden)] #[doc(hidden)]
pub trait PyMappingProtocolImpl { pub trait PyMappingProtocolImpl {
fn tp_as_mapping() -> Option<ffi::PyMappingMethods> { fn tp_as_mapping() -> Option<ffi::PyMappingMethods>;
fn methods() -> Vec<PyMethodDef>;
}
impl<T> PyMappingProtocolImpl for T {
default fn tp_as_mapping() -> Option<ffi::PyMappingMethods> {
None None
} }
fn methods() -> Vec<PyMethodDef> { default fn methods() -> Vec<PyMethodDef> {
Vec::new() Vec::new()
} }
} }
impl<T> PyMappingProtocolImpl for T {}
impl<'p, T> PyMappingProtocolImpl for T impl<'p, T> PyMappingProtocolImpl for T
where where
T: PyMappingProtocol<'p>, T: PyMappingProtocol<'p>,
@ -154,13 +157,18 @@ where
} }
trait PyMappingLenProtocolImpl { trait PyMappingLenProtocolImpl {
fn mp_length() -> Option<ffi::lenfunc> { fn mp_length() -> Option<ffi::lenfunc>;
}
impl<'p, T> PyMappingLenProtocolImpl for T
where
T: PyMappingProtocol<'p>,
{
default fn mp_length() -> Option<ffi::lenfunc> {
None None
} }
} }
impl<'p, T> PyMappingLenProtocolImpl for T where T: PyMappingProtocol<'p> {}
impl<T> PyMappingLenProtocolImpl for T impl<T> PyMappingLenProtocolImpl for T
where where
T: for<'p> PyMappingLenProtocol<'p>, T: for<'p> PyMappingLenProtocol<'p>,
@ -172,13 +180,18 @@ where
} }
trait PyMappingGetItemProtocolImpl { trait PyMappingGetItemProtocolImpl {
fn mp_subscript() -> Option<ffi::binaryfunc> { fn mp_subscript() -> Option<ffi::binaryfunc>;
}
impl<'p, T> PyMappingGetItemProtocolImpl for T
where
T: PyMappingProtocol<'p>,
{
default fn mp_subscript() -> Option<ffi::binaryfunc> {
None None
} }
} }
impl<'p, T> PyMappingGetItemProtocolImpl for T where T: PyMappingProtocol<'p> {}
impl<T> PyMappingGetItemProtocolImpl for T impl<T> PyMappingGetItemProtocolImpl for T
where where
T: for<'p> PyMappingGetItemProtocol<'p>, T: for<'p> PyMappingGetItemProtocol<'p>,
@ -195,13 +208,18 @@ where
} }
trait PyMappingSetItemProtocolImpl { trait PyMappingSetItemProtocolImpl {
fn mp_ass_subscript() -> Option<ffi::objobjargproc> { fn mp_ass_subscript() -> Option<ffi::objobjargproc>;
}
impl<'p, T> PyMappingSetItemProtocolImpl for T
where
T: PyMappingProtocol<'p>,
{
default fn mp_ass_subscript() -> Option<ffi::objobjargproc> {
None None
} }
} }
impl<'p, T> PyMappingSetItemProtocolImpl for T where T: PyMappingProtocol<'p> {}
impl<T> PyMappingSetItemProtocolImpl for T impl<T> PyMappingSetItemProtocolImpl for T
where where
T: for<'p> PyMappingSetItemProtocol<'p>, T: for<'p> PyMappingSetItemProtocol<'p>,
@ -215,22 +233,32 @@ where
/// Returns `None` if PyMappingDelItemProtocol isn't implemented, otherwise dispatches to /// Returns `None` if PyMappingDelItemProtocol isn't implemented, otherwise dispatches to
/// `DelSetItemDispatch` /// `DelSetItemDispatch`
trait DeplItemDipatch { trait DeplItemDipatch {
fn mp_del_subscript() -> Option<ffi::objobjargproc> { fn mp_del_subscript() -> Option<ffi::objobjargproc>;
}
impl<'p, T> DeplItemDipatch for T
where
T: PyMappingProtocol<'p>,
{
default fn mp_del_subscript() -> Option<ffi::objobjargproc> {
None None
} }
} }
impl<'p, T> DeplItemDipatch for T where T: PyMappingProtocol<'p> {}
/// Returns `py_func_set_del` if PyMappingSetItemProtocol is implemented, otherwise `py_func_del` /// Returns `py_func_set_del` if PyMappingSetItemProtocol is implemented, otherwise `py_func_del`
trait DelSetItemDispatch: Sized + for<'p> PyMappingDelItemProtocol<'p> { trait DelSetItemDispatch: Sized + for<'p> PyMappingDelItemProtocol<'p> {
fn det_set_dispatch() -> Option<ffi::objobjargproc> { fn det_set_dispatch() -> Option<ffi::objobjargproc>;
}
impl<T> DelSetItemDispatch for T
where
T: Sized + for<'p> PyMappingDelItemProtocol<'p>,
{
default fn det_set_dispatch() -> Option<ffi::objobjargproc> {
py_func_del!(PyMappingDelItemProtocol, Self, __delitem__) py_func_del!(PyMappingDelItemProtocol, Self, __delitem__)
} }
} }
impl<T> DelSetItemDispatch for T where T: Sized + for<'p> PyMappingDelItemProtocol<'p> {}
impl<T> DelSetItemDispatch for T impl<T> DelSetItemDispatch for T
where where
T: for<'p> PyMappingSetItemProtocol<'p> + for<'p> PyMappingDelItemProtocol<'p>, T: for<'p> PyMappingSetItemProtocol<'p> + for<'p> PyMappingDelItemProtocol<'p>,
@ -257,27 +285,42 @@ where
#[doc(hidden)] #[doc(hidden)]
pub trait PyMappingContainsProtocolImpl { pub trait PyMappingContainsProtocolImpl {
fn __contains__() -> Option<PyMethodDef> { fn __contains__() -> Option<PyMethodDef>;
}
impl<'p, T> PyMappingContainsProtocolImpl for T
where
T: PyMappingProtocol<'p>,
{
default fn __contains__() -> Option<PyMethodDef> {
None None
} }
} }
impl<'p, T> PyMappingContainsProtocolImpl for T where T: PyMappingProtocol<'p> {}
#[doc(hidden)] #[doc(hidden)]
pub trait PyMappingReversedProtocolImpl { pub trait PyMappingReversedProtocolImpl {
fn __reversed__() -> Option<PyMethodDef> { fn __reversed__() -> Option<PyMethodDef>;
}
impl<'p, T> PyMappingReversedProtocolImpl for T
where
T: PyMappingProtocol<'p>,
{
default fn __reversed__() -> Option<PyMethodDef> {
None None
} }
} }
impl<'p, T> PyMappingReversedProtocolImpl for T where T: PyMappingProtocol<'p> {}
#[doc(hidden)] #[doc(hidden)]
pub trait PyMappingIterProtocolImpl { pub trait PyMappingIterProtocolImpl {
fn __iter__() -> Option<PyMethodDef> { fn __iter__() -> Option<PyMethodDef>;
}
impl<'p, T> PyMappingIterProtocolImpl for T
where
T: PyMappingProtocol<'p>,
{
default fn __iter__() -> Option<PyMethodDef> {
None None
} }
} }
impl<'p, T> PyMappingIterProtocolImpl for T where T: PyMappingProtocol<'p> {}

View File

@ -622,10 +622,15 @@ pub trait PyNumberIndexProtocol<'p>: PyNumberProtocol<'p> {
#[doc(hidden)] #[doc(hidden)]
pub trait PyNumberProtocolImpl: PyObjectProtocolImpl { pub trait PyNumberProtocolImpl: PyObjectProtocolImpl {
fn methods() -> Vec<PyMethodDef> { fn methods() -> Vec<PyMethodDef>;
fn tp_as_number() -> Option<ffi::PyNumberMethods>;
}
impl<'p, T> PyNumberProtocolImpl for T {
default fn methods() -> Vec<PyMethodDef> {
Vec::new() Vec::new()
} }
fn tp_as_number() -> Option<ffi::PyNumberMethods> { default fn tp_as_number() -> Option<ffi::PyNumberMethods> {
if let Some(nb_bool) = <Self as PyObjectProtocolImpl>::nb_bool_fn() { if let Some(nb_bool) = <Self as PyObjectProtocolImpl>::nb_bool_fn() {
let meth = ffi::PyNumberMethods { let meth = ffi::PyNumberMethods {
nb_bool: Some(nb_bool), nb_bool: Some(nb_bool),
@ -638,8 +643,6 @@ pub trait PyNumberProtocolImpl: PyObjectProtocolImpl {
} }
} }
impl<'p, T> PyNumberProtocolImpl for T {}
impl<'p, T> PyNumberProtocolImpl for T impl<'p, T> PyNumberProtocolImpl for T
where where
T: PyNumberProtocol<'p>, T: PyNumberProtocol<'p>,
@ -743,13 +746,18 @@ where
} }
trait PyNumberAddProtocolImpl { trait PyNumberAddProtocolImpl {
fn nb_add() -> Option<ffi::binaryfunc> { fn nb_add() -> Option<ffi::binaryfunc>;
}
impl<'p, T> PyNumberAddProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn nb_add() -> Option<ffi::binaryfunc> {
None None
} }
} }
impl<'p, T> PyNumberAddProtocolImpl for T where T: PyNumberProtocol<'p> {}
impl<T> PyNumberAddProtocolImpl for T impl<T> PyNumberAddProtocolImpl for T
where where
T: for<'p> PyNumberAddProtocol<'p>, T: for<'p> PyNumberAddProtocol<'p>,
@ -765,13 +773,18 @@ where
} }
trait PyNumberSubProtocolImpl { trait PyNumberSubProtocolImpl {
fn nb_subtract() -> Option<ffi::binaryfunc> { fn nb_subtract() -> Option<ffi::binaryfunc>;
}
impl<'p, T> PyNumberSubProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn nb_subtract() -> Option<ffi::binaryfunc> {
None None
} }
} }
impl<'p, T> PyNumberSubProtocolImpl for T where T: PyNumberProtocol<'p> {}
impl<T> PyNumberSubProtocolImpl for T impl<T> PyNumberSubProtocolImpl for T
where where
T: for<'p> PyNumberSubProtocol<'p>, T: for<'p> PyNumberSubProtocol<'p>,
@ -787,13 +800,18 @@ where
} }
trait PyNumberMulProtocolImpl { trait PyNumberMulProtocolImpl {
fn nb_multiply() -> Option<ffi::binaryfunc> { fn nb_multiply() -> Option<ffi::binaryfunc>;
}
impl<'p, T> PyNumberMulProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn nb_multiply() -> Option<ffi::binaryfunc> {
None None
} }
} }
impl<'p, T> PyNumberMulProtocolImpl for T where T: PyNumberProtocol<'p> {}
impl<T> PyNumberMulProtocolImpl for T impl<T> PyNumberMulProtocolImpl for T
where where
T: for<'p> PyNumberMulProtocol<'p>, T: for<'p> PyNumberMulProtocol<'p>,
@ -809,13 +827,18 @@ where
} }
trait PyNumberMatmulProtocolImpl { trait PyNumberMatmulProtocolImpl {
fn nb_matrix_multiply() -> Option<ffi::binaryfunc> { fn nb_matrix_multiply() -> Option<ffi::binaryfunc>;
}
impl<'p, T> PyNumberMatmulProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn nb_matrix_multiply() -> Option<ffi::binaryfunc> {
None None
} }
} }
impl<'p, T> PyNumberMatmulProtocolImpl for T where T: PyNumberProtocol<'p> {}
impl<T> PyNumberMatmulProtocolImpl for T impl<T> PyNumberMatmulProtocolImpl for T
where where
T: for<'p> PyNumberMatmulProtocol<'p>, T: for<'p> PyNumberMatmulProtocol<'p>,
@ -831,13 +854,18 @@ where
} }
trait PyNumberTruedivProtocolImpl { trait PyNumberTruedivProtocolImpl {
fn nb_true_divide() -> Option<ffi::binaryfunc> { fn nb_true_divide() -> Option<ffi::binaryfunc>;
}
impl<'p, T> PyNumberTruedivProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn nb_true_divide() -> Option<ffi::binaryfunc> {
None None
} }
} }
impl<'p, T> PyNumberTruedivProtocolImpl for T where T: PyNumberProtocol<'p> {}
impl<T> PyNumberTruedivProtocolImpl for T impl<T> PyNumberTruedivProtocolImpl for T
where where
T: for<'p> PyNumberTruedivProtocol<'p>, T: for<'p> PyNumberTruedivProtocol<'p>,
@ -853,13 +881,18 @@ where
} }
trait PyNumberFloordivProtocolImpl { trait PyNumberFloordivProtocolImpl {
fn nb_floor_divide() -> Option<ffi::binaryfunc> { fn nb_floor_divide() -> Option<ffi::binaryfunc>;
}
impl<'p, T> PyNumberFloordivProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn nb_floor_divide() -> Option<ffi::binaryfunc> {
None None
} }
} }
impl<'p, T> PyNumberFloordivProtocolImpl for T where T: PyNumberProtocol<'p> {}
impl<T> PyNumberFloordivProtocolImpl for T impl<T> PyNumberFloordivProtocolImpl for T
where where
T: for<'p> PyNumberFloordivProtocol<'p>, T: for<'p> PyNumberFloordivProtocol<'p>,
@ -875,13 +908,18 @@ where
} }
trait PyNumberModProtocolImpl { trait PyNumberModProtocolImpl {
fn nb_remainder() -> Option<ffi::binaryfunc> { fn nb_remainder() -> Option<ffi::binaryfunc>;
}
impl<'p, T> PyNumberModProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn nb_remainder() -> Option<ffi::binaryfunc> {
None None
} }
} }
impl<'p, T> PyNumberModProtocolImpl for T where T: PyNumberProtocol<'p> {}
impl<T> PyNumberModProtocolImpl for T impl<T> PyNumberModProtocolImpl for T
where where
T: for<'p> PyNumberModProtocol<'p>, T: for<'p> PyNumberModProtocol<'p>,
@ -897,13 +935,18 @@ where
} }
trait PyNumberDivmodProtocolImpl { trait PyNumberDivmodProtocolImpl {
fn nb_divmod() -> Option<ffi::binaryfunc> { fn nb_divmod() -> Option<ffi::binaryfunc>;
}
impl<'p, T> PyNumberDivmodProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn nb_divmod() -> Option<ffi::binaryfunc> {
None None
} }
} }
impl<'p, T> PyNumberDivmodProtocolImpl for T where T: PyNumberProtocol<'p> {}
impl<T> PyNumberDivmodProtocolImpl for T impl<T> PyNumberDivmodProtocolImpl for T
where where
T: for<'p> PyNumberDivmodProtocol<'p>, T: for<'p> PyNumberDivmodProtocol<'p>,
@ -919,13 +962,18 @@ where
} }
trait PyNumberPowProtocolImpl { trait PyNumberPowProtocolImpl {
fn nb_power() -> Option<ffi::ternaryfunc> { fn nb_power() -> Option<ffi::ternaryfunc>;
}
impl<'p, T> PyNumberPowProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn nb_power() -> Option<ffi::ternaryfunc> {
None None
} }
} }
impl<'p, T> PyNumberPowProtocolImpl for T where T: PyNumberProtocol<'p> {}
impl<T> PyNumberPowProtocolImpl for T impl<T> PyNumberPowProtocolImpl for T
where where
T: for<'p> PyNumberPowProtocol<'p>, T: for<'p> PyNumberPowProtocol<'p>,
@ -941,13 +989,18 @@ where
} }
trait PyNumberLShiftProtocolImpl { trait PyNumberLShiftProtocolImpl {
fn nb_lshift() -> Option<ffi::binaryfunc> { fn nb_lshift() -> Option<ffi::binaryfunc>;
}
impl<'p, T> PyNumberLShiftProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn nb_lshift() -> Option<ffi::binaryfunc> {
None None
} }
} }
impl<'p, T> PyNumberLShiftProtocolImpl for T where T: PyNumberProtocol<'p> {}
impl<T> PyNumberLShiftProtocolImpl for T impl<T> PyNumberLShiftProtocolImpl for T
where where
T: for<'p> PyNumberLShiftProtocol<'p>, T: for<'p> PyNumberLShiftProtocol<'p>,
@ -963,13 +1016,18 @@ where
} }
trait PyNumberRShiftProtocolImpl { trait PyNumberRShiftProtocolImpl {
fn nb_rshift() -> Option<ffi::binaryfunc> { fn nb_rshift() -> Option<ffi::binaryfunc>;
}
impl<'p, T> PyNumberRShiftProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn nb_rshift() -> Option<ffi::binaryfunc> {
None None
} }
} }
impl<'p, T> PyNumberRShiftProtocolImpl for T where T: PyNumberProtocol<'p> {}
impl<T> PyNumberRShiftProtocolImpl for T impl<T> PyNumberRShiftProtocolImpl for T
where where
T: for<'p> PyNumberRShiftProtocol<'p>, T: for<'p> PyNumberRShiftProtocol<'p>,
@ -985,13 +1043,18 @@ where
} }
trait PyNumberAndProtocolImpl { trait PyNumberAndProtocolImpl {
fn nb_and() -> Option<ffi::binaryfunc> { fn nb_and() -> Option<ffi::binaryfunc>;
}
impl<'p, T> PyNumberAndProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn nb_and() -> Option<ffi::binaryfunc> {
None None
} }
} }
impl<'p, T> PyNumberAndProtocolImpl for T where T: PyNumberProtocol<'p> {}
impl<T> PyNumberAndProtocolImpl for T impl<T> PyNumberAndProtocolImpl for T
where where
T: for<'p> PyNumberAndProtocol<'p>, T: for<'p> PyNumberAndProtocol<'p>,
@ -1007,13 +1070,18 @@ where
} }
trait PyNumberXorProtocolImpl { trait PyNumberXorProtocolImpl {
fn nb_xor() -> Option<ffi::binaryfunc> { fn nb_xor() -> Option<ffi::binaryfunc>;
}
impl<'p, T> PyNumberXorProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn nb_xor() -> Option<ffi::binaryfunc> {
None None
} }
} }
impl<'p, T> PyNumberXorProtocolImpl for T where T: PyNumberProtocol<'p> {}
impl<T> PyNumberXorProtocolImpl for T impl<T> PyNumberXorProtocolImpl for T
where where
T: for<'p> PyNumberXorProtocol<'p>, T: for<'p> PyNumberXorProtocol<'p>,
@ -1029,13 +1097,18 @@ where
} }
trait PyNumberOrProtocolImpl { trait PyNumberOrProtocolImpl {
fn nb_or() -> Option<ffi::binaryfunc> { fn nb_or() -> Option<ffi::binaryfunc>;
}
impl<'p, T> PyNumberOrProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn nb_or() -> Option<ffi::binaryfunc> {
None None
} }
} }
impl<'p, T> PyNumberOrProtocolImpl for T where T: PyNumberProtocol<'p> {}
impl<T> PyNumberOrProtocolImpl for T impl<T> PyNumberOrProtocolImpl for T
where where
T: for<'p> PyNumberOrProtocol<'p>, T: for<'p> PyNumberOrProtocol<'p>,
@ -1051,13 +1124,18 @@ where
} }
trait PyNumberIAddProtocolImpl { trait PyNumberIAddProtocolImpl {
fn nb_inplace_add() -> Option<ffi::binaryfunc> { fn nb_inplace_add() -> Option<ffi::binaryfunc>;
}
impl<'p, T> PyNumberIAddProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn nb_inplace_add() -> Option<ffi::binaryfunc> {
None None
} }
} }
impl<'p, T> PyNumberIAddProtocolImpl for T where T: PyNumberProtocol<'p> {}
impl<T> PyNumberIAddProtocolImpl for T impl<T> PyNumberIAddProtocolImpl for T
where where
T: for<'p> PyNumberIAddProtocol<'p>, T: for<'p> PyNumberIAddProtocol<'p>,
@ -1068,13 +1146,18 @@ where
} }
trait PyNumberISubProtocolImpl { trait PyNumberISubProtocolImpl {
fn nb_inplace_subtract() -> Option<ffi::binaryfunc> { fn nb_inplace_subtract() -> Option<ffi::binaryfunc>;
}
impl<'p, T> PyNumberISubProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn nb_inplace_subtract() -> Option<ffi::binaryfunc> {
None None
} }
} }
impl<'p, T> PyNumberISubProtocolImpl for T where T: PyNumberProtocol<'p> {}
impl<T> PyNumberISubProtocolImpl for T impl<T> PyNumberISubProtocolImpl for T
where where
T: for<'p> PyNumberISubProtocol<'p>, T: for<'p> PyNumberISubProtocol<'p>,
@ -1085,13 +1168,18 @@ where
} }
trait PyNumberIMulProtocolImpl { trait PyNumberIMulProtocolImpl {
fn nb_inplace_multiply() -> Option<ffi::binaryfunc> { fn nb_inplace_multiply() -> Option<ffi::binaryfunc>;
}
impl<'p, T> PyNumberIMulProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn nb_inplace_multiply() -> Option<ffi::binaryfunc> {
None None
} }
} }
impl<'p, T> PyNumberIMulProtocolImpl for T where T: PyNumberProtocol<'p> {}
impl<T> PyNumberIMulProtocolImpl for T impl<T> PyNumberIMulProtocolImpl for T
where where
T: for<'p> PyNumberIMulProtocol<'p>, T: for<'p> PyNumberIMulProtocol<'p>,
@ -1102,13 +1190,18 @@ where
} }
trait PyNumberIMatmulProtocolImpl { trait PyNumberIMatmulProtocolImpl {
fn nb_inplace_matrix_multiply() -> Option<ffi::binaryfunc> { fn nb_inplace_matrix_multiply() -> Option<ffi::binaryfunc>;
}
impl<'p, T> PyNumberIMatmulProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn nb_inplace_matrix_multiply() -> Option<ffi::binaryfunc> {
None None
} }
} }
impl<'p, T> PyNumberIMatmulProtocolImpl for T where T: PyNumberProtocol<'p> {}
impl<T> PyNumberIMatmulProtocolImpl for T impl<T> PyNumberIMatmulProtocolImpl for T
where where
T: for<'p> PyNumberIMatmulProtocol<'p>, T: for<'p> PyNumberIMatmulProtocol<'p>,
@ -1119,13 +1212,18 @@ where
} }
trait PyNumberITruedivProtocolImpl { trait PyNumberITruedivProtocolImpl {
fn nb_inplace_true_divide() -> Option<ffi::binaryfunc> { fn nb_inplace_true_divide() -> Option<ffi::binaryfunc>;
}
impl<'p, T> PyNumberITruedivProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn nb_inplace_true_divide() -> Option<ffi::binaryfunc> {
None None
} }
} }
impl<'p, T> PyNumberITruedivProtocolImpl for T where T: PyNumberProtocol<'p> {}
impl<T> PyNumberITruedivProtocolImpl for T impl<T> PyNumberITruedivProtocolImpl for T
where where
T: for<'p> PyNumberITruedivProtocol<'p>, T: for<'p> PyNumberITruedivProtocol<'p>,
@ -1136,13 +1234,18 @@ where
} }
trait PyNumberIFloordivProtocolImpl { trait PyNumberIFloordivProtocolImpl {
fn nb_inplace_floor_divide() -> Option<ffi::binaryfunc> { fn nb_inplace_floor_divide() -> Option<ffi::binaryfunc>;
}
impl<'p, T> PyNumberIFloordivProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn nb_inplace_floor_divide() -> Option<ffi::binaryfunc> {
None None
} }
} }
impl<'p, T> PyNumberIFloordivProtocolImpl for T where T: PyNumberProtocol<'p> {}
impl<T> PyNumberIFloordivProtocolImpl for T impl<T> PyNumberIFloordivProtocolImpl for T
where where
T: for<'p> PyNumberIFloordivProtocol<'p>, T: for<'p> PyNumberIFloordivProtocol<'p>,
@ -1153,13 +1256,18 @@ where
} }
trait PyNumberIModProtocolImpl { trait PyNumberIModProtocolImpl {
fn nb_inplace_remainder() -> Option<ffi::binaryfunc> { fn nb_inplace_remainder() -> Option<ffi::binaryfunc>;
}
impl<'p, T> PyNumberIModProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn nb_inplace_remainder() -> Option<ffi::binaryfunc> {
None None
} }
} }
impl<'p, T> PyNumberIModProtocolImpl for T where T: PyNumberProtocol<'p> {}
impl<T> PyNumberIModProtocolImpl for T impl<T> PyNumberIModProtocolImpl for T
where where
T: for<'p> PyNumberIModProtocol<'p>, T: for<'p> PyNumberIModProtocol<'p>,
@ -1170,13 +1278,18 @@ where
} }
trait PyNumberIPowProtocolImpl { trait PyNumberIPowProtocolImpl {
fn nb_inplace_power() -> Option<ffi::ternaryfunc> { fn nb_inplace_power() -> Option<ffi::ternaryfunc>;
}
impl<'p, T> PyNumberIPowProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn nb_inplace_power() -> Option<ffi::ternaryfunc> {
None None
} }
} }
impl<'p, T> PyNumberIPowProtocolImpl for T where T: PyNumberProtocol<'p> {}
impl<T> PyNumberIPowProtocolImpl for T impl<T> PyNumberIPowProtocolImpl for T
where where
T: for<'p> PyNumberIPowProtocol<'p>, T: for<'p> PyNumberIPowProtocol<'p>,
@ -1187,13 +1300,18 @@ where
} }
trait PyNumberILShiftProtocolImpl { trait PyNumberILShiftProtocolImpl {
fn nb_inplace_lshift() -> Option<ffi::binaryfunc> { fn nb_inplace_lshift() -> Option<ffi::binaryfunc>;
}
impl<'p, T> PyNumberILShiftProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn nb_inplace_lshift() -> Option<ffi::binaryfunc> {
None None
} }
} }
impl<'p, T> PyNumberILShiftProtocolImpl for T where T: PyNumberProtocol<'p> {}
impl<T> PyNumberILShiftProtocolImpl for T impl<T> PyNumberILShiftProtocolImpl for T
where where
T: for<'p> PyNumberILShiftProtocol<'p>, T: for<'p> PyNumberILShiftProtocol<'p>,
@ -1204,13 +1322,18 @@ where
} }
trait PyNumberIRShiftProtocolImpl { trait PyNumberIRShiftProtocolImpl {
fn nb_inplace_rshift() -> Option<ffi::binaryfunc> { fn nb_inplace_rshift() -> Option<ffi::binaryfunc>;
}
impl<'p, T> PyNumberIRShiftProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn nb_inplace_rshift() -> Option<ffi::binaryfunc> {
None None
} }
} }
impl<'p, T> PyNumberIRShiftProtocolImpl for T where T: PyNumberProtocol<'p> {}
impl<T> PyNumberIRShiftProtocolImpl for T impl<T> PyNumberIRShiftProtocolImpl for T
where where
T: for<'p> PyNumberIRShiftProtocol<'p>, T: for<'p> PyNumberIRShiftProtocol<'p>,
@ -1221,13 +1344,18 @@ where
} }
trait PyNumberIAndProtocolImpl { trait PyNumberIAndProtocolImpl {
fn nb_inplace_and() -> Option<ffi::binaryfunc> { fn nb_inplace_and() -> Option<ffi::binaryfunc>;
}
impl<'p, T> PyNumberIAndProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn nb_inplace_and() -> Option<ffi::binaryfunc> {
None None
} }
} }
impl<'p, T> PyNumberIAndProtocolImpl for T where T: PyNumberProtocol<'p> {}
impl<T> PyNumberIAndProtocolImpl for T impl<T> PyNumberIAndProtocolImpl for T
where where
T: for<'p> PyNumberIAndProtocol<'p>, T: for<'p> PyNumberIAndProtocol<'p>,
@ -1238,13 +1366,18 @@ where
} }
trait PyNumberIXorProtocolImpl { trait PyNumberIXorProtocolImpl {
fn nb_inplace_xor() -> Option<ffi::binaryfunc> { fn nb_inplace_xor() -> Option<ffi::binaryfunc>;
}
impl<'p, T> PyNumberIXorProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn nb_inplace_xor() -> Option<ffi::binaryfunc> {
None None
} }
} }
impl<'p, T> PyNumberIXorProtocolImpl for T where T: PyNumberProtocol<'p> {}
impl<T> PyNumberIXorProtocolImpl for T impl<T> PyNumberIXorProtocolImpl for T
where where
T: for<'p> PyNumberIXorProtocol<'p>, T: for<'p> PyNumberIXorProtocol<'p>,
@ -1255,13 +1388,18 @@ where
} }
trait PyNumberIOrProtocolImpl { trait PyNumberIOrProtocolImpl {
fn nb_inplace_or() -> Option<ffi::binaryfunc> { fn nb_inplace_or() -> Option<ffi::binaryfunc>;
}
impl<'p, T> PyNumberIOrProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn nb_inplace_or() -> Option<ffi::binaryfunc> {
None None
} }
} }
impl<'p, T> PyNumberIOrProtocolImpl for T where T: PyNumberProtocol<'p> {}
impl<T> PyNumberIOrProtocolImpl for T impl<T> PyNumberIOrProtocolImpl for T
where where
T: for<'p> PyNumberIOrProtocol<'p>, T: for<'p> PyNumberIOrProtocol<'p>,
@ -1273,13 +1411,18 @@ where
#[doc(hidden)] #[doc(hidden)]
pub trait PyNumberRAddProtocolImpl { pub trait PyNumberRAddProtocolImpl {
fn __radd__() -> Option<PyMethodDef> { fn __radd__() -> Option<PyMethodDef>;
}
impl<'p, T> PyNumberRAddProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn __radd__() -> Option<PyMethodDef> {
None None
} }
} }
impl<'p, T> PyNumberRAddProtocolImpl for T where T: PyNumberProtocol<'p> {}
#[doc(hidden)] #[doc(hidden)]
pub trait PyNumberRSubProtocolImpl { pub trait PyNumberRSubProtocolImpl {
fn __rsub__() -> Option<PyMethodDef> { fn __rsub__() -> Option<PyMethodDef> {
@ -1291,120 +1434,185 @@ impl<'p, T> PyNumberRSubProtocolImpl for T where T: PyNumberProtocol<'p> {}
#[doc(hidden)] #[doc(hidden)]
pub trait PyNumberRMulProtocolImpl { pub trait PyNumberRMulProtocolImpl {
fn __rmul__() -> Option<PyMethodDef> { fn __rmul__() -> Option<PyMethodDef>;
}
impl<'p, T> PyNumberRMulProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn __rmul__() -> Option<PyMethodDef> {
None None
} }
} }
impl<'p, T> PyNumberRMulProtocolImpl for T where T: PyNumberProtocol<'p> {}
#[doc(hidden)] #[doc(hidden)]
pub trait PyNumberRMatmulProtocolImpl { pub trait PyNumberRMatmulProtocolImpl {
fn __rmatmul__() -> Option<PyMethodDef> { fn __rmatmul__() -> Option<PyMethodDef>;
}
impl<'p, T> PyNumberRMatmulProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn __rmatmul__() -> Option<PyMethodDef> {
None None
} }
} }
impl<'p, T> PyNumberRMatmulProtocolImpl for T where T: PyNumberProtocol<'p> {}
#[doc(hidden)] #[doc(hidden)]
pub trait PyNumberRTruedivProtocolImpl { pub trait PyNumberRTruedivProtocolImpl {
fn __rtruediv__() -> Option<PyMethodDef> { fn __rtruediv__() -> Option<PyMethodDef>;
}
impl<'p, T> PyNumberRTruedivProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn __rtruediv__() -> Option<PyMethodDef> {
None None
} }
} }
impl<'p, T> PyNumberRTruedivProtocolImpl for T where T: PyNumberProtocol<'p> {}
#[doc(hidden)] #[doc(hidden)]
pub trait PyNumberRFloordivProtocolImpl { pub trait PyNumberRFloordivProtocolImpl {
fn __rfloordiv__() -> Option<PyMethodDef> { fn __rfloordiv__() -> Option<PyMethodDef>;
}
impl<'p, T> PyNumberRFloordivProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn __rfloordiv__() -> Option<PyMethodDef> {
None None
} }
} }
impl<'p, T> PyNumberRFloordivProtocolImpl for T where T: PyNumberProtocol<'p> {}
#[doc(hidden)] #[doc(hidden)]
pub trait PyNumberRModProtocolImpl { pub trait PyNumberRModProtocolImpl {
fn __rmod__() -> Option<PyMethodDef> { fn __rmod__() -> Option<PyMethodDef>;
}
impl<'p, T> PyNumberRModProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn __rmod__() -> Option<PyMethodDef> {
None None
} }
} }
impl<'p, T> PyNumberRModProtocolImpl for T where T: PyNumberProtocol<'p> {}
#[doc(hidden)] #[doc(hidden)]
pub trait PyNumberRDivmodProtocolImpl { pub trait PyNumberRDivmodProtocolImpl {
fn __rdivmod__() -> Option<PyMethodDef> { fn __rdivmod__() -> Option<PyMethodDef>;
}
impl<'p, T> PyNumberRDivmodProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn __rdivmod__() -> Option<PyMethodDef> {
None None
} }
} }
impl<'p, T> PyNumberRDivmodProtocolImpl for T where T: PyNumberProtocol<'p> {}
#[doc(hidden)] #[doc(hidden)]
pub trait PyNumberRPowProtocolImpl { pub trait PyNumberRPowProtocolImpl {
fn __rpow__() -> Option<PyMethodDef> { fn __rpow__() -> Option<PyMethodDef>;
}
impl<'p, T> PyNumberRPowProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn __rpow__() -> Option<PyMethodDef> {
None None
} }
} }
impl<'p, T> PyNumberRPowProtocolImpl for T where T: PyNumberProtocol<'p> {}
#[doc(hidden)] #[doc(hidden)]
pub trait PyNumberRLShiftProtocolImpl { pub trait PyNumberRLShiftProtocolImpl {
fn __rlshift__() -> Option<PyMethodDef> { fn __rlshift__() -> Option<PyMethodDef>;
}
impl<'p, T> PyNumberRLShiftProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn __rlshift__() -> Option<PyMethodDef> {
None None
} }
} }
impl<'p, T> PyNumberRLShiftProtocolImpl for T where T: PyNumberProtocol<'p> {}
#[doc(hidden)] #[doc(hidden)]
pub trait PyNumberRRShiftProtocolImpl { pub trait PyNumberRRShiftProtocolImpl {
fn __rrshift__() -> Option<PyMethodDef> { fn __rrshift__() -> Option<PyMethodDef>;
}
impl<'p, T> PyNumberRRShiftProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn __rrshift__() -> Option<PyMethodDef> {
None None
} }
} }
impl<'p, T> PyNumberRRShiftProtocolImpl for T where T: PyNumberProtocol<'p> {}
#[doc(hidden)] #[doc(hidden)]
pub trait PyNumberRAndProtocolImpl { pub trait PyNumberRAndProtocolImpl {
fn __rand__() -> Option<PyMethodDef> { fn __rand__() -> Option<PyMethodDef>;
}
impl<'p, T> PyNumberRAndProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn __rand__() -> Option<PyMethodDef> {
None None
} }
} }
impl<'p, T> PyNumberRAndProtocolImpl for T where T: PyNumberProtocol<'p> {}
#[doc(hidden)] #[doc(hidden)]
pub trait PyNumberRXorProtocolImpl { pub trait PyNumberRXorProtocolImpl {
fn __rxor__() -> Option<PyMethodDef> { fn __rxor__() -> Option<PyMethodDef>;
}
impl<'p, T> PyNumberRXorProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn __rxor__() -> Option<PyMethodDef> {
None None
} }
} }
impl<'p, T> PyNumberRXorProtocolImpl for T where T: PyNumberProtocol<'p> {}
#[doc(hidden)] #[doc(hidden)]
pub trait PyNumberROrProtocolImpl { pub trait PyNumberROrProtocolImpl {
fn __ror__() -> Option<PyMethodDef> { fn __ror__() -> Option<PyMethodDef>;
}
impl<'p, T> PyNumberROrProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn __ror__() -> Option<PyMethodDef> {
None None
} }
} }
impl<'p, T> PyNumberROrProtocolImpl for T where T: PyNumberProtocol<'p> {}
trait PyNumberNegProtocolImpl { trait PyNumberNegProtocolImpl {
fn nb_negative() -> Option<ffi::unaryfunc> { fn nb_negative() -> Option<ffi::unaryfunc>;
}
impl<'p, T> PyNumberNegProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn nb_negative() -> Option<ffi::unaryfunc> {
None None
} }
} }
impl<'p, T> PyNumberNegProtocolImpl for T where T: PyNumberProtocol<'p> {}
impl<T> PyNumberNegProtocolImpl for T impl<T> PyNumberNegProtocolImpl for T
where where
T: for<'p> PyNumberNegProtocol<'p>, T: for<'p> PyNumberNegProtocol<'p>,
@ -1421,13 +1629,18 @@ where
} }
trait PyNumberPosProtocolImpl { trait PyNumberPosProtocolImpl {
fn nb_positive() -> Option<ffi::unaryfunc> { fn nb_positive() -> Option<ffi::unaryfunc>;
}
impl<'p, T> PyNumberPosProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn nb_positive() -> Option<ffi::unaryfunc> {
None None
} }
} }
impl<'p, T> PyNumberPosProtocolImpl for T where T: PyNumberProtocol<'p> {}
impl<T> PyNumberPosProtocolImpl for T impl<T> PyNumberPosProtocolImpl for T
where where
T: for<'p> PyNumberPosProtocol<'p>, T: for<'p> PyNumberPosProtocol<'p>,
@ -1443,13 +1656,18 @@ where
} }
trait PyNumberAbsProtocolImpl { trait PyNumberAbsProtocolImpl {
fn nb_absolute() -> Option<ffi::unaryfunc> { fn nb_absolute() -> Option<ffi::unaryfunc>;
}
impl<'p, T> PyNumberAbsProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn nb_absolute() -> Option<ffi::unaryfunc> {
None None
} }
} }
impl<'p, T> PyNumberAbsProtocolImpl for T where T: PyNumberProtocol<'p> {}
impl<T> PyNumberAbsProtocolImpl for T impl<T> PyNumberAbsProtocolImpl for T
where where
T: for<'p> PyNumberAbsProtocol<'p>, T: for<'p> PyNumberAbsProtocol<'p>,
@ -1465,13 +1683,18 @@ where
} }
trait PyNumberInvertProtocolImpl { trait PyNumberInvertProtocolImpl {
fn nb_invert() -> Option<ffi::unaryfunc> { fn nb_invert() -> Option<ffi::unaryfunc>;
}
impl<'p, T> PyNumberInvertProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn nb_invert() -> Option<ffi::unaryfunc> {
None None
} }
} }
impl<'p, T> PyNumberInvertProtocolImpl for T where T: PyNumberProtocol<'p> {}
impl<T> PyNumberInvertProtocolImpl for T impl<T> PyNumberInvertProtocolImpl for T
where where
T: for<'p> PyNumberInvertProtocol<'p>, T: for<'p> PyNumberInvertProtocol<'p>,
@ -1487,13 +1710,18 @@ where
} }
trait PyNumberIntProtocolImpl { trait PyNumberIntProtocolImpl {
fn nb_int() -> Option<ffi::unaryfunc> { fn nb_int() -> Option<ffi::unaryfunc>;
}
impl<'p, T> PyNumberIntProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn nb_int() -> Option<ffi::unaryfunc> {
None None
} }
} }
impl<'p, T> PyNumberIntProtocolImpl for T where T: PyNumberProtocol<'p> {}
impl<T> PyNumberIntProtocolImpl for T impl<T> PyNumberIntProtocolImpl for T
where where
T: for<'p> PyNumberIntProtocol<'p>, T: for<'p> PyNumberIntProtocol<'p>,
@ -1509,13 +1737,18 @@ where
} }
trait PyNumberFloatProtocolImpl { trait PyNumberFloatProtocolImpl {
fn nb_float() -> Option<ffi::unaryfunc> { fn nb_float() -> Option<ffi::unaryfunc>;
}
impl<'p, T> PyNumberFloatProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn nb_float() -> Option<ffi::unaryfunc> {
None None
} }
} }
impl<'p, T> PyNumberFloatProtocolImpl for T where T: PyNumberProtocol<'p> {}
impl<T> PyNumberFloatProtocolImpl for T impl<T> PyNumberFloatProtocolImpl for T
where where
T: for<'p> PyNumberFloatProtocol<'p>, T: for<'p> PyNumberFloatProtocol<'p>,
@ -1531,13 +1764,18 @@ where
} }
trait PyNumberIndexProtocolImpl { trait PyNumberIndexProtocolImpl {
fn nb_index() -> Option<ffi::unaryfunc> { fn nb_index() -> Option<ffi::unaryfunc>;
}
impl<'p, T> PyNumberIndexProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn nb_index() -> Option<ffi::unaryfunc> {
None None
} }
} }
impl<'p, T> PyNumberIndexProtocolImpl for T where T: PyNumberProtocol<'p> {}
impl<T> PyNumberIndexProtocolImpl for T impl<T> PyNumberIndexProtocolImpl for T
where where
T: for<'p> PyNumberIndexProtocol<'p>, T: for<'p> PyNumberIndexProtocol<'p>,
@ -1553,17 +1791,27 @@ where
} }
trait PyNumberComplexProtocolImpl { trait PyNumberComplexProtocolImpl {
fn __complex__() -> Option<PyMethodDef> { fn __complex__() -> Option<PyMethodDef>;
}
impl<'p, T> PyNumberComplexProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn __complex__() -> Option<PyMethodDef> {
None None
} }
} }
impl<'p, T> PyNumberComplexProtocolImpl for T where T: PyNumberProtocol<'p> {}
trait PyNumberRoundProtocolImpl { trait PyNumberRoundProtocolImpl {
fn __round__() -> Option<PyMethodDef> { fn __round__() -> Option<PyMethodDef>;
}
impl<'p, T> PyNumberRoundProtocolImpl for T
where
T: PyNumberProtocol<'p>,
{
default fn __round__() -> Option<PyMethodDef> {
None None
} }
} }
impl<'p, T> PyNumberRoundProtocolImpl for T where T: PyNumberProtocol<'p> {}

View File

@ -91,17 +91,20 @@ pub trait PyAsyncAexitProtocol<'p>: PyAsyncProtocol<'p> {
#[doc(hidden)] #[doc(hidden)]
pub trait PyAsyncProtocolImpl { pub trait PyAsyncProtocolImpl {
fn tp_as_async() -> Option<ffi::PyAsyncMethods> { fn tp_as_async() -> Option<ffi::PyAsyncMethods>;
fn methods() -> Vec<PyMethodDef>;
}
impl<T> PyAsyncProtocolImpl for T {
default fn tp_as_async() -> Option<ffi::PyAsyncMethods> {
None None
} }
fn methods() -> Vec<PyMethodDef> { default fn methods() -> Vec<PyMethodDef> {
Vec::new() Vec::new()
} }
} }
impl<T> PyAsyncProtocolImpl for T {}
impl<'p, T> PyAsyncProtocolImpl for T impl<'p, T> PyAsyncProtocolImpl for T
where where
T: PyAsyncProtocol<'p>, T: PyAsyncProtocol<'p>,
@ -131,13 +134,18 @@ where
} }
trait PyAsyncAwaitProtocolImpl { trait PyAsyncAwaitProtocolImpl {
fn am_await() -> Option<ffi::unaryfunc> { fn am_await() -> Option<ffi::unaryfunc>;
}
impl<'p, T> PyAsyncAwaitProtocolImpl for T
where
T: PyAsyncProtocol<'p>,
{
default fn am_await() -> Option<ffi::unaryfunc> {
None None
} }
} }
impl<'p, T> PyAsyncAwaitProtocolImpl for T where T: PyAsyncProtocol<'p> {}
impl<T> PyAsyncAwaitProtocolImpl for T impl<T> PyAsyncAwaitProtocolImpl for T
where where
T: for<'p> PyAsyncAwaitProtocol<'p>, T: for<'p> PyAsyncAwaitProtocol<'p>,
@ -154,13 +162,18 @@ where
} }
trait PyAsyncAiterProtocolImpl { trait PyAsyncAiterProtocolImpl {
fn am_aiter() -> Option<ffi::unaryfunc> { fn am_aiter() -> Option<ffi::unaryfunc>;
}
impl<'p, T> PyAsyncAiterProtocolImpl for T
where
T: PyAsyncProtocol<'p>,
{
default fn am_aiter() -> Option<ffi::unaryfunc> {
None None
} }
} }
impl<'p, T> PyAsyncAiterProtocolImpl for T where T: PyAsyncProtocol<'p> {}
impl<T> PyAsyncAiterProtocolImpl for T impl<T> PyAsyncAiterProtocolImpl for T
where where
T: for<'p> PyAsyncAiterProtocol<'p>, T: for<'p> PyAsyncAiterProtocol<'p>,
@ -177,13 +190,18 @@ where
} }
trait PyAsyncAnextProtocolImpl { trait PyAsyncAnextProtocolImpl {
fn am_anext() -> Option<ffi::unaryfunc> { fn am_anext() -> Option<ffi::unaryfunc>;
}
impl<'p, T> PyAsyncAnextProtocolImpl for T
where
T: PyAsyncProtocol<'p>,
{
default fn am_anext() -> Option<ffi::unaryfunc> {
None None
} }
} }
impl<'p, T> PyAsyncAnextProtocolImpl for T where T: PyAsyncProtocol<'p> {}
mod anext { mod anext {
use super::{PyAsyncAnextProtocol, PyAsyncAnextProtocolImpl}; use super::{PyAsyncAnextProtocol, PyAsyncAnextProtocolImpl};
use crate::callback::CallbackConverter; use crate::callback::CallbackConverter;
@ -233,17 +251,27 @@ mod anext {
} }
trait PyAsyncAenterProtocolImpl { trait PyAsyncAenterProtocolImpl {
fn __aenter__() -> Option<PyMethodDef> { fn __aenter__() -> Option<PyMethodDef>;
}
impl<'p, T> PyAsyncAenterProtocolImpl for T
where
T: PyAsyncProtocol<'p>,
{
default fn __aenter__() -> Option<PyMethodDef> {
None None
} }
} }
impl<'p, T> PyAsyncAenterProtocolImpl for T where T: PyAsyncProtocol<'p> {}
trait PyAsyncAexitProtocolImpl { trait PyAsyncAexitProtocolImpl {
fn __aexit__() -> Option<PyMethodDef> { fn __aexit__() -> Option<PyMethodDef>;
}
impl<'p, T> PyAsyncAexitProtocolImpl for T
where
T: PyAsyncProtocol<'p>,
{
default fn __aexit__() -> Option<PyMethodDef> {
None None
} }
} }
impl<'p, T> PyAsyncAexitProtocolImpl for T where T: PyAsyncProtocol<'p> {}

View File

@ -134,13 +134,15 @@ pub trait PySequenceInplaceRepeatProtocol<'p>: PySequenceProtocol<'p> + IntoPy<P
#[doc(hidden)] #[doc(hidden)]
pub trait PySequenceProtocolImpl { pub trait PySequenceProtocolImpl {
fn tp_as_sequence() -> Option<ffi::PySequenceMethods> { fn tp_as_sequence() -> Option<ffi::PySequenceMethods>;
}
impl<T> PySequenceProtocolImpl for T {
default fn tp_as_sequence() -> Option<ffi::PySequenceMethods> {
None None
} }
} }
impl<T> PySequenceProtocolImpl for T {}
impl<'p, T> PySequenceProtocolImpl for T impl<'p, T> PySequenceProtocolImpl for T
where where
T: PySequenceProtocol<'p>, T: PySequenceProtocol<'p>,
@ -162,13 +164,18 @@ where
} }
trait PySequenceLenProtocolImpl { trait PySequenceLenProtocolImpl {
fn sq_length() -> Option<ffi::lenfunc> { fn sq_length() -> Option<ffi::lenfunc>;
}
impl<'p, T> PySequenceLenProtocolImpl for T
where
T: PySequenceProtocol<'p>,
{
default fn sq_length() -> Option<ffi::lenfunc> {
None None
} }
} }
impl<'p, T> PySequenceLenProtocolImpl for T where T: PySequenceProtocol<'p> {}
impl<T> PySequenceLenProtocolImpl for T impl<T> PySequenceLenProtocolImpl for T
where where
T: for<'p> PySequenceLenProtocol<'p>, T: for<'p> PySequenceLenProtocol<'p>,
@ -179,13 +186,18 @@ where
} }
trait PySequenceGetItemProtocolImpl { trait PySequenceGetItemProtocolImpl {
fn sq_item() -> Option<ffi::ssizeargfunc> { fn sq_item() -> Option<ffi::ssizeargfunc>;
}
impl<'p, T> PySequenceGetItemProtocolImpl for T
where
T: PySequenceProtocol<'p>,
{
default fn sq_item() -> Option<ffi::ssizeargfunc> {
None None
} }
} }
impl<'p, T> PySequenceGetItemProtocolImpl for T where T: PySequenceProtocol<'p> {}
impl<T> PySequenceGetItemProtocolImpl for T impl<T> PySequenceGetItemProtocolImpl for T
where where
T: for<'p> PySequenceGetItemProtocol<'p>, T: for<'p> PySequenceGetItemProtocol<'p>,
@ -201,13 +213,18 @@ where
} }
trait PySequenceSetItemProtocolImpl { trait PySequenceSetItemProtocolImpl {
fn sq_ass_item() -> Option<ffi::ssizeobjargproc> { fn sq_ass_item() -> Option<ffi::ssizeobjargproc>;
}
impl<'p, T> PySequenceSetItemProtocolImpl for T
where
T: PySequenceProtocol<'p>,
{
default fn sq_ass_item() -> Option<ffi::ssizeobjargproc> {
None None
} }
} }
impl<'p, T> PySequenceSetItemProtocolImpl for T where T: PySequenceProtocol<'p> {}
impl<T> PySequenceSetItemProtocolImpl for T impl<T> PySequenceSetItemProtocolImpl for T
where where
T: for<'p> PySequenceSetItemProtocol<'p>, T: for<'p> PySequenceSetItemProtocol<'p>,
@ -275,13 +292,18 @@ mod sq_ass_item_impl {
} }
trait DelItem { trait DelItem {
fn del_item() -> Option<ffi::ssizeobjargproc> { fn del_item() -> Option<ffi::ssizeobjargproc>;
}
impl<'p, T> DelItem for T
where
T: PySequenceProtocol<'p>,
{
default fn del_item() -> Option<ffi::ssizeobjargproc> {
None None
} }
} }
impl<'p, T> DelItem for T where T: PySequenceProtocol<'p> {}
impl<T> DelItem for T impl<T> DelItem for T
where where
T: for<'p> PySequenceDelItemProtocol<'p>, T: for<'p> PySequenceDelItemProtocol<'p>,
@ -321,13 +343,18 @@ mod sq_ass_item_impl {
} }
trait DelSetItem { trait DelSetItem {
fn del_set_item() -> Option<ffi::ssizeobjargproc> { fn del_set_item() -> Option<ffi::ssizeobjargproc>;
}
impl<'p, T> DelSetItem for T
where
T: PySequenceProtocol<'p>,
{
default fn del_set_item() -> Option<ffi::ssizeobjargproc> {
None None
} }
} }
impl<'p, T> DelSetItem for T where T: PySequenceProtocol<'p> {}
impl<T> DelSetItem for T impl<T> DelSetItem for T
where where
T: for<'p> PySequenceSetItemProtocol<'p> + for<'p> PySequenceDelItemProtocol<'p>, T: for<'p> PySequenceSetItemProtocol<'p> + for<'p> PySequenceDelItemProtocol<'p>,
@ -368,13 +395,18 @@ mod sq_ass_item_impl {
} }
trait PySequenceContainsProtocolImpl { trait PySequenceContainsProtocolImpl {
fn sq_contains() -> Option<ffi::objobjproc> { fn sq_contains() -> Option<ffi::objobjproc>;
}
impl<'p, T> PySequenceContainsProtocolImpl for T
where
T: PySequenceProtocol<'p>,
{
default fn sq_contains() -> Option<ffi::objobjproc> {
None None
} }
} }
impl<'p, T> PySequenceContainsProtocolImpl for T where T: PySequenceProtocol<'p> {}
impl<T> PySequenceContainsProtocolImpl for T impl<T> PySequenceContainsProtocolImpl for T
where where
T: for<'p> PySequenceContainsProtocol<'p>, T: for<'p> PySequenceContainsProtocol<'p>,
@ -391,13 +423,18 @@ where
} }
trait PySequenceConcatProtocolImpl { trait PySequenceConcatProtocolImpl {
fn sq_concat() -> Option<ffi::binaryfunc> { fn sq_concat() -> Option<ffi::binaryfunc>;
}
impl<'p, T> PySequenceConcatProtocolImpl for T
where
T: PySequenceProtocol<'p>,
{
default fn sq_concat() -> Option<ffi::binaryfunc> {
None None
} }
} }
impl<'p, T> PySequenceConcatProtocolImpl for T where T: PySequenceProtocol<'p> {}
impl<T> PySequenceConcatProtocolImpl for T impl<T> PySequenceConcatProtocolImpl for T
where where
T: for<'p> PySequenceConcatProtocol<'p>, T: for<'p> PySequenceConcatProtocol<'p>,
@ -413,13 +450,18 @@ where
} }
trait PySequenceRepeatProtocolImpl { trait PySequenceRepeatProtocolImpl {
fn sq_repeat() -> Option<ffi::ssizeargfunc> { fn sq_repeat() -> Option<ffi::ssizeargfunc>;
}
impl<'p, T> PySequenceRepeatProtocolImpl for T
where
T: PySequenceProtocol<'p>,
{
default fn sq_repeat() -> Option<ffi::ssizeargfunc> {
None None
} }
} }
impl<'p, T> PySequenceRepeatProtocolImpl for T where T: PySequenceProtocol<'p> {}
impl<T> PySequenceRepeatProtocolImpl for T impl<T> PySequenceRepeatProtocolImpl for T
where where
T: for<'p> PySequenceRepeatProtocol<'p>, T: for<'p> PySequenceRepeatProtocol<'p>,
@ -435,13 +477,18 @@ where
} }
trait PySequenceInplaceConcatProtocolImpl { trait PySequenceInplaceConcatProtocolImpl {
fn sq_inplace_concat() -> Option<ffi::binaryfunc> { fn sq_inplace_concat() -> Option<ffi::binaryfunc>;
}
impl<'p, T> PySequenceInplaceConcatProtocolImpl for T
where
T: PySequenceProtocol<'p>,
{
default fn sq_inplace_concat() -> Option<ffi::binaryfunc> {
None None
} }
} }
impl<'p, T> PySequenceInplaceConcatProtocolImpl for T where T: PySequenceProtocol<'p> {}
impl<T> PySequenceInplaceConcatProtocolImpl for T impl<T> PySequenceInplaceConcatProtocolImpl for T
where where
T: for<'p> PySequenceInplaceConcatProtocol<'p>, T: for<'p> PySequenceInplaceConcatProtocol<'p>,
@ -457,13 +504,18 @@ where
} }
trait PySequenceInplaceRepeatProtocolImpl { trait PySequenceInplaceRepeatProtocolImpl {
fn sq_inplace_repeat() -> Option<ffi::ssizeargfunc> { fn sq_inplace_repeat() -> Option<ffi::ssizeargfunc>;
}
impl<'p, T> PySequenceInplaceRepeatProtocolImpl for T
where
T: PySequenceProtocol<'p>,
{
default fn sq_inplace_repeat() -> Option<ffi::ssizeargfunc> {
None None
} }
} }
impl<'p, T> PySequenceInplaceRepeatProtocolImpl for T where T: PySequenceProtocol<'p> {}
impl<T> PySequenceInplaceRepeatProtocolImpl for T impl<T> PySequenceInplaceRepeatProtocolImpl for T
where where
T: for<'p> PySequenceInplaceRepeatProtocol<'p>, T: for<'p> PySequenceInplaceRepeatProtocol<'p>,

View File

@ -96,6 +96,15 @@ pub trait ToBorrowedObject: ToPyObject {
/// May be more efficient than `to_object` because it does not need /// May be more efficient than `to_object` because it does not need
/// to touch any reference counts when the input object already is a Python object. /// to touch any reference counts when the input object already is a Python object.
fn with_borrowed_ptr<F, R>(&self, py: Python, f: F) -> R fn with_borrowed_ptr<F, R>(&self, py: Python, f: F) -> R
where
F: FnOnce(*mut ffi::PyObject) -> R;
}
impl<T> ToBorrowedObject for T
where
T: ToPyObject,
{
default fn with_borrowed_ptr<F, R>(&self, py: Python, f: F) -> R
where where
F: FnOnce(*mut ffi::PyObject) -> R, F: FnOnce(*mut ffi::PyObject) -> R,
{ {
@ -108,8 +117,6 @@ pub trait ToBorrowedObject: ToPyObject {
} }
} }
impl<T> ToBorrowedObject for T where T: ToPyObject {}
impl<T> ToBorrowedObject for T impl<T> ToBorrowedObject for T
where where
T: ToPyObject + AsPyPointer, T: ToPyObject + AsPyPointer,

View File

@ -359,13 +359,18 @@ impl<T> Py<T> {
/// Specialization workaround /// Specialization workaround
trait AsPyRefDispatch<T: PyTypeInfo>: AsPyPointer { trait AsPyRefDispatch<T: PyTypeInfo>: AsPyPointer {
fn as_ref_dispatch(&self, _py: Python) -> &T { fn as_ref_dispatch(&self, _py: Python) -> &T;
fn as_mut_dispatch(&mut self, _py: Python) -> &mut T;
}
impl<T: PyTypeInfo> AsPyRefDispatch<T> for Py<T> {
default fn as_ref_dispatch(&self, _py: Python) -> &T {
unsafe { unsafe {
let ptr = (self.as_ptr() as *mut u8).offset(T::OFFSET) as *mut T; let ptr = (self.as_ptr() as *mut u8).offset(T::OFFSET) as *mut T;
ptr.as_ref().expect("Py has a null pointer") ptr.as_ref().expect("Py has a null pointer")
} }
} }
fn as_mut_dispatch(&mut self, _py: Python) -> &mut T { default fn as_mut_dispatch(&mut self, _py: Python) -> &mut T {
unsafe { unsafe {
let ptr = (self.as_ptr() as *mut u8).offset(T::OFFSET) as *mut T; let ptr = (self.as_ptr() as *mut u8).offset(T::OFFSET) as *mut T;
ptr.as_mut().expect("Py has a null pointer") ptr.as_mut().expect("Py has a null pointer")
@ -373,8 +378,6 @@ trait AsPyRefDispatch<T: PyTypeInfo>: AsPyPointer {
} }
} }
impl<T: PyTypeInfo> AsPyRefDispatch<T> for Py<T> {}
impl<T: PyTypeInfo + PyNativeType> AsPyRefDispatch<T> for Py<T> { impl<T: PyTypeInfo + PyNativeType> AsPyRefDispatch<T> for Py<T> {
fn as_ref_dispatch(&self, _py: Python) -> &T { fn as_ref_dispatch(&self, _py: Python) -> &T {
unsafe { &*(self as *const instance::Py<T> as *const T) } unsafe { &*(self as *const instance::Py<T> as *const T) }
@ -553,22 +556,10 @@ impl<'p, T: ToPyObject> AsPyPointer for ManagedPyRef<'p, T> {
/// Helper trait to choose the right implementation for [ManagedPyRef] /// Helper trait to choose the right implementation for [ManagedPyRef]
pub trait ManagedPyRefDispatch: ToPyObject { pub trait ManagedPyRefDispatch: ToPyObject {
/// Optionally converts into a python object and stores the pointer to the python heap. /// Optionally converts into a python object and stores the pointer to the python heap.
/// fn to_managed_py_ref<'p>(&self, py: Python<'p>) -> ManagedPyRef<'p, Self>;
/// Contains the case 1 impl (with to_object) to avoid a specialization error
fn to_managed_py_ref<'p>(&self, py: Python<'p>) -> ManagedPyRef<'p, Self> {
ManagedPyRef {
data: self.to_object(py).into_ptr(),
data_type: PhantomData,
_py: py,
}
}
/// Dispatch over a xdecref and a noop drop impl /// Dispatch over a xdecref and a noop drop impl
/// fn drop_impl(borrowed: &mut ManagedPyRef<Self>);
/// Contains the case 1 impl (decref) to avoid a specialization error
fn drop_impl(borrowed: &mut ManagedPyRef<Self>) {
unsafe { ffi::Py_DECREF(borrowed.data) };
}
} }
/// Case 1: It's a rust object which still needs to be converted to a python object. /// Case 1: It's a rust object which still needs to be converted to a python object.
@ -577,7 +568,21 @@ pub trait ManagedPyRefDispatch: ToPyObject {
/// ///
/// Note that the actual implementations are part of the trait declaration to avoid /// Note that the actual implementations are part of the trait declaration to avoid
/// a specialization error /// a specialization error
impl<T: ToPyObject + ?Sized> ManagedPyRefDispatch for T {} impl<T: ToPyObject + ?Sized> ManagedPyRefDispatch for T {
/// Contains the case 1 impl (with to_object) to avoid a specialization error
default fn to_managed_py_ref<'p>(&self, py: Python<'p>) -> ManagedPyRef<'p, Self> {
ManagedPyRef {
data: self.to_object(py).into_ptr(),
data_type: PhantomData,
_py: py,
}
}
/// Contains the case 1 impl (decref) to avoid a specialization error
default fn drop_impl(borrowed: &mut ManagedPyRef<Self>) {
unsafe { ffi::Py_DECREF(borrowed.data) };
}
}
/// Case 2: It's an object on the python heap, we're just storing a borrowed pointer. /// Case 2: It's an object on the python heap, we're just storing a borrowed pointer.
/// The object we're getting is an owned pointer, it might have it's own drop impl. /// The object we're getting is an owned pointer, it might have it's own drop impl.