pyo3_special_method_derive 0.4.3

Automatically derive Python dunder methods for your Rust code
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use pyo3::pyclass;
use pyo3_special_method_derive::Str;

#[pyclass]
#[derive(Str)]
#[format(fmt = "Struct: {}({})")]
struct Data(
    #[format(fmt = "{}")] pub usize,
    #[format(fmt = "[{}]")] pub f32,
);

#[test]
fn test_formatter_struct() {
    let data = Data(5, 1.23);

    assert_eq!(data.__str__(), "Struct: Data(0=5, 1=[1.23])");
}