Skip to content

Commit

Permalink
Add documentation related to from_py_with for the FromPyObject trait
Browse files Browse the repository at this point in the history
  • Loading branch information
ricohageman committed Feb 24, 2022
1 parent fc186cd commit ed698c4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 4 additions & 0 deletions guide/src/conversions/traits.md
Expand Up @@ -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>`

Expand Down
5 changes: 1 addition & 4 deletions tests/test_frompyobject.rs
Expand Up @@ -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() {
Expand Down

0 comments on commit ed698c4

Please sign in to comment.