Expand description
Derive macros to make Rust objects more friendly 🤗.
Please see these docs for the PyDisplay and PyDebug
traits which power Str and Repr.
This crate automatically derives the following functions for structs and enums:
-
__str__ -
__repr__ -
__dir__ -
__getattr__ -
__dict__ -
Skip exposure of variants or fields per derive macro with the
#[skip(...)]attribute (eg.#[skip(Dir, Str)]) -
Struct fields which are not
pubare skipped automatically
When you have custom Rust structs which need to implement PyDisplay and PyDebug, you should use the AutoDisplay and AutoDebug traits.
This will have the same output as Str and Repr respectively.
This crate exports 2 traits (PyDisplay`` and PyDebug`) which should be implemented for every type for which its field or variant is not skipped.
It also exports a macro to use the Debug and Display traits to generate a PyDebug and PyDisplay
implementation.
In addition, the AutoDisplay and AutoDebug macros enable usage of arbitrary Rust, non-pyclass structs.
Macros§
- pydebug_
pydisplay - Use this trait to automatically derive PyDebug and PyDisplay for your type. It uses the Debug and Display traits internally. Because this usage can expose Rust semantics, types, or otherwise look foreign, this should only be used for types which are simple enough to not be distinctly Rust-y.
Statics§
- ELLIPSIS_
CHAR_ N - Number of characters to display for each implementation in this crate, defaults to 100. May be a few chars above or below.
Traits§
- PyDebug
- Types which can be displayed into the
__repr__implementation. - PyDisplay
- Types which can be displayed into the
__str__implementation.
Attribute Macros§
Derive Macros§
- Auto
Debug - Implement
PyDebugon a struct or enum. ImplementsDebugbased onPyDebugif the type does not. - Auto
Display - Implement
PyDisplayon a struct or enum. ImplementsDisplaybased onPyDisplayif the type does not. - Dict
- Add a
__dict__attribute to a struct or enum. - Dir
- Add a
__dir__method to a struct or enum. - Getattr
- Add a
__getattr__method to a struct or enum. - Repr
- Add a
__repr__method to the struct or enum. - Str
- Add a
__str__method to the struct or enum.