pyo3_special_method_derive_macro

Crates.iopyo3_special_method_derive_macro
lib.rspyo3_special_method_derive_macro
version0.4.2
sourcesrc
created_at2024-07-19 19:56:15.000902
updated_at2024-07-20 00:40:21.298142
descriptionAutomatically derive Python dunder methods for your Rust code
homepage
repositoryhttps://github.com/EricLBuehler/pyo3-special-method-derive
max_upload_size
id1309034
size48,385
Eric Buehler (EricLBuehler)

documentation

README

pyo3-special-method-derive

This crate enables you to automatically derive Python dunder methods for your Rust crate using PyO3.

Key features

  • The following methods may be automatically derived on structs and enums:
    • __str__
    • __repr__
    • __dir__
    • __getattr__
    • __dict__
  • Support for structs and enums (only unit and complex enums due to a PyO3 limitation)
  • Support for skipping variants or fields with the #[pyo3_smd(skip)] attribute
  • Automatically skip struct fields which are not pub
  • Support for skipping variants or fields for __str__ or __repr__ differently with the #[pyo3_smd_str(skip)] and #[pyo3_smd_str(repr)] attributes

Example

#[pyclass]
#[derive(Dir, Str, Repr)]
struct Person {
    pub name: String,
    occupation: String,
    #[pyo3_smd(skip)]
    pub phone_num: String,
}

PyO3 feature note

To use pyo3-special-method-derive, you should enable the multiple-pymethods feature on PyO3:

pyo3 = { version = "0.22", features = ["multiple-pymethods"] }
Commit count: 36

cargo fmt