| 600 | new_members=[('$name', '$init')]) |
| 601 | |
| 602 | def property_method(): |
| 603 | def impl(with_visibility): |
| 604 | if with_visibility: |
| 605 | visibility_capture = '$visibility:vis' |
| 606 | visibility_expansion = '$visibility' |
| 607 | else: |
| 608 | visibility_capture = '' |
| 609 | visibility_expansion = 'pub' |
| 610 | |
| 611 | generate_case('$(#[doc=$doc:expr])* @property %s def $name:ident(&$slf:ident) -> $res_type:ty { $( $body:tt )* }' % (visibility_capture,), |
| 612 | new_impl='$crate::py_class_impl_item! { $class, $py, %s, $name(&$slf,) $res_type; { $($body)* } [] }' % (visibility_expansion,), |
| 613 | new_props=([('concat!($($doc, "\\n"),*)', '$name', '$res_type')], []) |
| 614 | ) |
| 615 | generate_case('@$name:ident.setter %s def $setter_name:ident(&$slf:ident, $value:ident : Option<Option<&$value_type:ty>> ) -> $res_type:ty { $( $body:tt )* }' % (visibility_capture,), |
| 616 | new_impl='$crate::py_class_impl_item! { $class, $py, %s, $setter_name(&$slf,) $res_type; { $($body)* } [{ $value: Option<Option<&$value_type>> = {} }] }' % (visibility_expansion,), |
| 617 | new_props=([], [('$name', 'Option<&$value_type>', '$setter_name')]) |
| 618 | ) |
| 619 | generate_case('@$name:ident.setter %s def $setter_name:ident(&$slf:ident, $value:ident : Option<&$value_type:ty> ) -> $res_type:ty { $( $body:tt )* }' % (visibility_capture,), |
| 620 | new_impl='$crate::py_class_impl_item! { $class, $py, %s, $setter_name(&$slf,) $res_type; { $($body)* } [{ $value: Option<&$value_type> = {} }] }' % (visibility_expansion,), |
| 621 | new_props=([], [('$name', '&$value_type', '$setter_name')]) |
| 622 | ) |
| 623 | generate_case('@$name:ident.setter %s def $setter_name:ident(&$slf:ident, $value:ident : Option<$value_type:ty> ) -> $res_type:ty { $( $body:tt )* }' % (visibility_capture,), |
| 624 | new_impl='$crate::py_class_impl_item! { $class, $py, %s, $setter_name(&$slf,) $res_type; { $($body)* } [{ $value: Option<$value_type> = {} }] }' % (visibility_expansion,), |
| 625 | new_props=([], [('$name', '$value_type', '$setter_name')]) |
| 626 | ) |
| 627 | |
| 628 | for with_visibility in (False, True): |
| 629 | impl(with_visibility) |
| 630 | |
| 631 | macro_end = ''' |
| 632 | } |