Skip to content

Commit

Permalink
Merge pull request #767 from gilescope/more-docs
Browse files Browse the repository at this point in the history
(docs update) Focusing on FromPy rather than IntoPy
  • Loading branch information
kngwyu authored Feb 15, 2020
2 parents 7910dfc + 6b4a4e8 commit 0b5918e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions guide/src/conversions.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,11 @@ fn main() {
}
```

## `IntoPy<T>`
## `FromPy<T>` and `IntoPy<T>`

Many conversions in PyO3 can't use `std::convert::Into` because they need a GIL token. That's why the `IntoPy<T>` trait offers an `into_py` method that works just like `into`, except for taking a `Python<'_>` argument.
Many conversions in PyO3 can't use `std::convert::From` because they need a GIL token. The `FromPy<T>` trait offers an `from_py` method that works just like `from`, except for taking a `Python<'_>` argument. I.e. FromPy<T> could be converting a rust object into a python object even though it says `FromPy` - it doesn't say anything about which side of the conversion is a python object.

(Just like From<T>, if you implement FromPy<T> you gain a blanket implementation of IntoPy<T> for free.)

Eventually, traits such as `ToPyObject` will be replaced by this trait and a `FromPy` trait will be added that will implement `IntoPy`, just like with `From` and `Into`.

Expand Down

0 comments on commit 0b5918e

Please sign in to comment.