gen_methods_from_python!() { /* proc-macro */ }
Expand description
Generate PyMethodsInfo from Python class definition
This proc-macro parses Python class definition syntax and generates a PyMethodsInfo structure.
It should be used inside inventory::submit!
blocks.
Supports single or multiple method definitions within a class:
ⓘ
// Single method
submit! {
gen_methods_from_python! {
r#"
class Incrementer:
def increment_1(self, x: int) -> int:
"""Increment by one"""
"#
}
}
// Multiple methods
submit! {
gen_methods_from_python! {
r#"
class Incrementer2:
def increment_2(self, x: float) -> float:
"""Increment by two (float version)"""
def __new__(cls) -> Incrementer2:
"""Constructor"""
def increment_2(self, x: int) -> int:
"""Increment by two (int version)"""
"#
}
}