Skip to content

Commit b6ff541

Browse files
authored
Create ContentItem with a macro (#5859)
* Create ContentItem with a macro * Set struct docs via metadata
1 parent 7c6d063 commit b6ff541

File tree

1 file changed

+45
-62
lines changed

1 file changed

+45
-62
lines changed

derive-impl/src/pyclass.rs

Lines changed: 45 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -653,72 +653,55 @@ pub(crate) fn impl_pyexception_impl(attr: PunctuatedNestedMeta, item: Item) -> R
653653
})
654654
}
655655

656-
/// #[pymethod] and #[pyclassmethod]
657-
struct MethodItem {
658-
inner: ContentItemInner<AttrName>,
659-
}
660-
661-
/// #[pygetset]
662-
struct GetSetItem {
663-
inner: ContentItemInner<AttrName>,
664-
}
665-
666-
/// #[pyslot]
667-
struct SlotItem {
668-
inner: ContentItemInner<AttrName>,
669-
}
670-
671-
/// #[pyattr]
672-
struct AttributeItem {
673-
inner: ContentItemInner<AttrName>,
674-
}
656+
macro_rules! define_content_item {
657+
(
658+
$(#[$meta:meta])*
659+
$vis:vis struct $name:ident
660+
) => {
661+
$(#[$meta])*
662+
$vis struct $name {
663+
inner: ContentItemInner<AttrName>,
664+
}
675665

676-
/// #[extend_class]
677-
struct ExtendClassItem {
678-
inner: ContentItemInner<AttrName>,
679-
}
666+
impl ContentItem for $name {
667+
type AttrName = AttrName;
680668

681-
/// #[pymember]
682-
struct MemberItem {
683-
inner: ContentItemInner<AttrName>,
669+
fn inner(&self) -> &ContentItemInner<AttrName> {
670+
&self.inner
671+
}
672+
}
673+
};
684674
}
685675

686-
impl ContentItem for MethodItem {
687-
type AttrName = AttrName;
688-
fn inner(&self) -> &ContentItemInner<AttrName> {
689-
&self.inner
690-
}
691-
}
692-
impl ContentItem for GetSetItem {
693-
type AttrName = AttrName;
694-
fn inner(&self) -> &ContentItemInner<AttrName> {
695-
&self.inner
696-
}
697-
}
698-
impl ContentItem for SlotItem {
699-
type AttrName = AttrName;
700-
fn inner(&self) -> &ContentItemInner<AttrName> {
701-
&self.inner
702-
}
703-
}
704-
impl ContentItem for AttributeItem {
705-
type AttrName = AttrName;
706-
fn inner(&self) -> &ContentItemInner<AttrName> {
707-
&self.inner
708-
}
709-
}
710-
impl ContentItem for ExtendClassItem {
711-
type AttrName = AttrName;
712-
fn inner(&self) -> &ContentItemInner<AttrName> {
713-
&self.inner
714-
}
715-
}
716-
impl ContentItem for MemberItem {
717-
type AttrName = AttrName;
718-
fn inner(&self) -> &ContentItemInner<AttrName> {
719-
&self.inner
720-
}
721-
}
676+
define_content_item!(
677+
/// #[pymethod] and #[pyclassmethod]
678+
struct MethodItem
679+
);
680+
681+
define_content_item!(
682+
/// #[pygetset]
683+
struct GetSetItem
684+
);
685+
686+
define_content_item!(
687+
/// #[pyslot]
688+
struct SlotItem
689+
);
690+
691+
define_content_item!(
692+
/// #[pyattr]
693+
struct AttributeItem
694+
);
695+
696+
define_content_item!(
697+
/// #[extend_class]
698+
struct ExtendClassItem
699+
);
700+
701+
define_content_item!(
702+
/// #[pymember]
703+
struct MemberItem
704+
);
722705

723706
struct ImplItemArgs<'a, Item: ItemLike> {
724707
item: &'a Item,

0 commit comments

Comments
 (0)