Use $(;$generics)* instead of generics: <$(;$generics)+>

This commit is contained in:
kngwyu 2020-12-15 17:26:22 +09:00 committed by David Hewitt
parent f8d408f3b5
commit b341dffd4f
1 changed files with 33 additions and 33 deletions

View File

@ -30,10 +30,10 @@ pub use self::typeobject::PyType;
// Implementations core to all native types
#[macro_export]
macro_rules! pyobject_native_type_base(
($name: ty $(,generics: <$($generics:ident),+>)?) => {
unsafe impl<$($($generics),+)?> $crate::PyNativeType for $name {}
($name: ty $(;$generics: ident)* ) => {
unsafe impl<$($generics,)*> $crate::PyNativeType for $name {}
impl<$($($generics),+)?> ::std::fmt::Debug for $name {
impl<$($generics,)*> ::std::fmt::Debug for $name {
fn fmt(&self, f: &mut ::std::fmt::Formatter)
-> Result<(), ::std::fmt::Error>
{
@ -42,7 +42,7 @@ macro_rules! pyobject_native_type_base(
}
}
impl<$($($generics),+)?> ::std::fmt::Display for $name {
impl<$($generics,)*> ::std::fmt::Display for $name {
fn fmt(&self, f: &mut ::std::fmt::Formatter)
-> Result<(), ::std::fmt::Error>
{
@ -51,7 +51,7 @@ macro_rules! pyobject_native_type_base(
}
}
impl<$($($generics),+)?> $crate::ToPyObject for $name
impl<$($generics,)*> $crate::ToPyObject for $name
{
#[inline]
fn to_object(&self, py: $crate::Python) -> $crate::PyObject {
@ -60,7 +60,7 @@ macro_rules! pyobject_native_type_base(
}
}
impl<$($($generics),+)?> PartialEq for $name {
impl<$($generics,)*> PartialEq for $name {
#[inline]
fn eq(&self, o: &$name) -> bool {
use $crate::AsPyPointer;
@ -75,17 +75,17 @@ macro_rules! pyobject_native_type_base(
// make sense on PyAny / have different implementations).
#[macro_export]
macro_rules! pyobject_native_type_named (
($name: ty $(,generics: <$($generics:ident),+>)?) => {
$crate::pyobject_native_type_base!($name $(,generics: <$($generics),+>)?);
($name: ty $(;$generics: ident)*) => {
$crate::pyobject_native_type_base!($name $(;$generics)*);
impl<$($($generics),+)?> ::std::convert::AsRef<$crate::PyAny> for $name {
impl<$($generics,)*> ::std::convert::AsRef<$crate::PyAny> for $name {
#[inline]
fn as_ref(&self) -> &$crate::PyAny {
&self.0
}
}
impl<$($($generics),+)?> ::std::ops::Deref for $name {
impl<$($generics,)*> ::std::ops::Deref for $name {
type Target = $crate::PyAny;
#[inline]
@ -94,7 +94,7 @@ macro_rules! pyobject_native_type_named (
}
}
impl<$($($generics),+)?> $crate::AsPyPointer for $name {
impl<$($generics,)*> $crate::AsPyPointer for $name {
/// Gets the underlying FFI pointer, returns a borrowed pointer.
#[inline]
fn as_ptr(&self) -> *mut $crate::ffi::PyObject {
@ -102,7 +102,7 @@ macro_rules! pyobject_native_type_named (
}
}
impl<$($($generics),+)?> $crate::IntoPy<$crate::Py<$name>> for &'_ $name {
impl<$($generics,)*> $crate::IntoPy<$crate::Py<$name>> for &'_ $name {
#[inline]
fn into_py(self, py: $crate::Python) -> $crate::Py<$name> {
use $crate::AsPyPointer;
@ -110,7 +110,7 @@ macro_rules! pyobject_native_type_named (
}
}
impl<$($($generics),+)?> From<&'_ $name> for $crate::Py<$name> {
impl<$($generics,)*> From<&'_ $name> for $crate::Py<$name> {
#[inline]
fn from(other: &$name) -> Self {
use $crate::AsPyPointer;
@ -119,7 +119,7 @@ macro_rules! pyobject_native_type_named (
}
}
impl<'a, $($($generics),+)?> ::std::convert::From<&'a $name> for &'a $crate::PyAny {
impl<'a, $($generics,)*> ::std::convert::From<&'a $name> for &'a $crate::PyAny {
fn from(ob: &'a $name) -> Self {
unsafe{&*(ob as *const $name as *const $crate::PyAny)}
}
@ -129,21 +129,21 @@ macro_rules! pyobject_native_type_named (
#[macro_export]
macro_rules! pyobject_native_type_core {
($name: ty, $layout: path, $typeobject: expr, $module: expr $(, $checkfunction:path)? $(,generics: <$($generics:ident),+>)? ) => {
($name: ty, $layout: path, $typeobject: expr, $module: expr $(, $checkfunction:path)? $(;$generics: ident)*) => {
unsafe impl $crate::type_object::PyLayout<$name> for $layout {}
$crate::pyobject_native_type_named!($name $(,generics: <$($generics),+>)?);
$crate::pyobject_native_type_info!($name, $layout, $typeobject, $module $(, $checkfunction)? $(,generics: <$($generics),+>)?);
$crate::pyobject_native_type_extract!($name $(,generics: <$($generics),+>)?);
$crate::pyobject_native_type_named!($name $(;$generics)*);
$crate::pyobject_native_type_info!($name, $layout, $typeobject, $module $(, $checkfunction)? $(;$generics)*);
$crate::pyobject_native_type_extract!($name $(;$generics)*);
}
}
#[macro_export]
macro_rules! pyobject_native_type_sized {
($name: ty, $layout: path $(,generics: <$($generics:ident),+>)?) => {
($name: ty, $layout: path $(;$generics: ident)*) => {
// To prevent inheriting native types with ABI3
#[cfg(not(Py_LIMITED_API))]
impl $crate::type_object::PySizedLayout<$name> for $layout {}
impl<'a, $($($generics),+)?> $crate::derive_utils::PyBaseTypeUtils for $name {
impl<'a, $($generics,)*> $crate::derive_utils::PyBaseTypeUtils for $name {
type Dict = $crate::pyclass_slots::PyClassDummySlot;
type WeakRef = $crate::pyclass_slots::PyClassDummySlot;
type LayoutAsBase = $crate::pycell::PyCellBase<$name>;
@ -155,26 +155,26 @@ macro_rules! pyobject_native_type_sized {
#[macro_export]
macro_rules! pyobject_native_type {
($name: ty, $layout: path, $typeobject: expr, $module: expr, $checkfunction:path $(,generics: <$($generics:ident),+>)?) => {
$crate::pyobject_native_type_core!($name, $layout, $typeobject, $module, $checkfunction $(,generics: <$($generics),+>)?);
$crate::pyobject_native_type_sized!($name, $layout $(,generics: <$($generics),+>)?);
($name: ty, $layout: path, $typeobject: expr, $module: expr, $checkfunction:path $(;$generics: ident)*) => {
$crate::pyobject_native_type_core!($name, $layout, $typeobject, $module, $checkfunction $(;$generics)*);
$crate::pyobject_native_type_sized!($name, $layout $(;$generics)*);
};
($name: ty, $layout: path, $typeobject: expr, $checkfunction:path $(,generics: <$($generics:ident),+>)?) => {
($name: ty, $layout: path, $typeobject: expr, $checkfunction:path $(;$generics: ident)*) => {
$crate::pyobject_native_type! {
$name, $layout, $typeobject, Some("builtins"), $checkfunction $(,generics: <$($generics),+>)?
$name, $layout, $typeobject, Some("builtins"), $checkfunction $(;$generics)*
}
};
}
#[macro_export]
macro_rules! pyobject_native_var_type {
($name: ty, $typeobject: expr, $module: expr, $checkfunction:path $(,generics: <$($generics:ident),+>)?) => {
($name: ty, $typeobject: expr, $module: expr, $checkfunction:path $(;$generics: ident)*) => {
$crate::pyobject_native_type_core!(
$name, $crate::ffi::PyObject, $typeobject, Some("builtins"), $checkfunction $(,generics: <$($generics),+>)?);
$name, $crate::ffi::PyObject, $typeobject, Some("builtins"), $checkfunction $(;$generics)*);
};
($name: ty, $typeobject: expr, $checkfunction: path $(,generics: <$($generics:ident),+>)?) => {
($name: ty, $typeobject: expr, $checkfunction: path $(;$generics: ident)*) => {
$crate::pyobject_native_var_type! {
$name, $typeobject, Some("builtins"), $checkfunction $(,generics: <$($generics),+>)?
$name, $typeobject, Some("builtins"), $checkfunction $(;$generics)*
}
};
}
@ -183,8 +183,8 @@ macro_rules! pyobject_native_var_type {
// because rust-numpy has a special implementation.
#[macro_export]
macro_rules! pyobject_native_type_extract {
($name: ty $(,generics: <$($generics:ident),+>)?) => {
impl<'py, $($($generics),+)?> $crate::FromPyObject<'py> for &'py $name {
($name: ty $(;$generics: ident)*) => {
impl<'py, $($generics,)*> $crate::FromPyObject<'py> for &'py $name {
fn extract(obj: &'py $crate::PyAny) -> $crate::PyResult<Self> {
$crate::PyTryFrom::try_from(obj).map_err(Into::into)
}
@ -195,8 +195,8 @@ macro_rules! pyobject_native_type_extract {
#[macro_export]
macro_rules! pyobject_native_type_info(
($name: ty, $layout: path, $typeobject: expr,
$module: expr $(, $checkfunction:path)? $(,generics: <$($generics:ident),+>)?) => {
unsafe impl<$($($generics),+)?> $crate::type_object::PyTypeInfo for $name {
$module: expr $(, $checkfunction:path)? $(;$generics: ident)*) => {
unsafe impl<$($generics,)*> $crate::type_object::PyTypeInfo for $name {
type Type = ();
type BaseType = $crate::PyAny;
type Layout = $layout;