Add documentation related to from_py_with for the FromPyObject trait

This commit is contained in:
Rico Hageman 2022-02-24 22:21:55 +01:00
parent fc186cdb3b
commit ed698c4b43
2 changed files with 5 additions and 4 deletions

View File

@ -442,6 +442,10 @@ If the input is neither a string nor an integer, the error message will be:
- `pyo3(item)`, `pyo3(item("key"))`
- retrieve the field from a mapping, possibly with the custom key specified as an argument.
- can be any literal that implements `ToBorrowedObject`
- `pyo3(from_py_with = "...")`
- apply a custom function to convert the field from Python the desired Rust type.
- the argument must be the name of the function as a string.
- the function signature must be `fn(&PyAny) -> PyResult<T>` where `T` is the Rust type of the argument.
### `IntoPy<T>`

View File

@ -483,10 +483,7 @@ fn test_from_py_with() {
}
#[derive(Debug, FromPyObject)]
pub struct ZapTuple(
String,
#[pyo3(from_py_with = "PyAny::len")] usize,
);
pub struct ZapTuple(String, #[pyo3(from_py_with = "PyAny::len")] usize);
#[test]
fn test_from_py_with_tuple_struct() {