(special_name=None, decoration='',
slot=None, add_member=False, value_macro=None, value_args=None)
| 425 | ''') |
| 426 | |
| 427 | def generate_class_method(special_name=None, decoration='', |
| 428 | slot=None, add_member=False, value_macro=None, value_args=None): |
| 429 | name_pattern = special_name or '$name:ident' |
| 430 | name_use = special_name or '$name' |
| 431 | def impl(with_params, with_docs, with_visibility): |
| 432 | if with_docs: |
| 433 | doc_prefix = '$(#[doc=$doc:expr])*' |
| 434 | value_suffix = ', { concat!($($doc, "\\n"),*) }' |
| 435 | else: |
| 436 | doc_prefix = value_suffix = '' |
| 437 | if with_visibility: |
| 438 | visibility_capture = '$visibility:vis' |
| 439 | visibility_expansion = '$visibility' |
| 440 | else: |
| 441 | visibility_capture = '' |
| 442 | visibility_expansion = 'pub' |
| 443 | if with_params: |
| 444 | param_pattern = ', $($p:tt)+' |
| 445 | impl = '''$crate::py_argparse_parse_plist_impl!{ |
| 446 | py_class_impl_item { $class, $py, %s, %s($cls: &$crate::PyType,) $res_type; { $($body)* } } |
| 447 | [] ($($p)+,) |
| 448 | }''' % (visibility_expansion, name_use) |
| 449 | value = '$crate::py_argparse_parse_plist_impl!{%s {%s} [] ($($p)+,)}' \ |
| 450 | % (value_macro, value_args + value_suffix) |
| 451 | else: |
| 452 | param_pattern = '' |
| 453 | impl = '$crate::py_class_impl_item! { $class, $py, %s, %s($cls: &$crate::PyType,) $res_type; { $($body)* } [] }' \ |
| 454 | % (visibility_expansion,name_use) |
| 455 | value = '$crate::%s!{%s []}' % (value_macro, value_args + value_suffix) |
| 456 | pattern = '%s %s def %s ($cls:ident%s) -> $res_type:ty { $( $body:tt )* }' \ |
| 457 | % (doc_prefix + decoration, visibility_capture, name_pattern, param_pattern) |
| 458 | slots = [] |
| 459 | if slot is not None: |
| 460 | slots.append((slot, value)) |
| 461 | members = [] |
| 462 | if add_member: |
| 463 | members.append((name_use, value)) |
| 464 | generate_case(pattern, new_impl=impl, new_slots=slots, new_members=members) |
| 465 | |
| 466 | # Special methods can't handle docs. |
| 467 | with_docs = (value_macro == 'py_class_class_method') |
| 468 | for with_params in (False, True): |
| 469 | for with_visibility in (False, True): |
| 470 | impl(with_params, with_docs, with_visibility) |
| 471 | |
| 472 | def traverse_and_clear(): |
| 473 | generate_case('def __traverse__(&$slf:tt, $visit:ident) {$($body:tt)*}', |
no test coverage detected