Dict-Derive
Derive macro for PyO3's FromPyObject
and IntoPyObject
traits. The derived implementation turns a Python's dict into your Rust struct and back.
Usage
Add the library to your Cargo.toml
together with PyO3:
[dependencies]
pyo3 = "0.7.0"
dict_derive = "0.1.2"
Import the derive implementation and use it on your structs:
extern crate dict_derive;
use ;
Then you can use your structs as arguments and return values in your PyO3 functions:
extern crate pyo3;
use *;
use wrap_pyfunction;
// Requires FromPyObject to receive a struct as an argument
// Requires IntoPyObject to return a struct
And then call your functions using normal python dicts:
>>> import mylib
>>> mylib.get_contact_info({"name": "Thor", "email": "thor@asgard.com", "age": 23})
'Thor - thor@asgard.com'
>>> mylib.get_default_user()
{'name': 'Default', 'email': 'default@user.com', 'age': 27}