#[pyclass]
This is supported on crate feature
macros
only.Expand description
A proc macro used to expose Rust structs and fieldless enums as Python objects.
#[pyclass]
accepts the following parameters:
Parameter | Description |
---|---|
name = "python_name" | Sets the name that Python sees this class as. Defaults to the name of the Rust struct. |
freelist = N | Implements a free list of size N. This can improve performance for types that are often created and deleted in quick succession. Profile your code to see whether freelist is right for you. |
weakref | Allows this class to be weakly referenceable. |
extends = BaseType | Use a custom baseclass. Defaults to PyAny |
subclass | Allows other Python classes and #[pyclass] to inherit from this class. Enums cannot be subclassed. |
unsendable | Required if your struct is not Send . Rather than using unsendable , consider implementing your struct in a threadsafe way by e.g. substituting Rc with Arc . By using unsendable , your class will panic when accessed by another thread. |
module = "module_name" | Python code will see the class as being defined in this module. Defaults to builtins . |
For more on creating Python classes, see the class section of the guide.