Skip to content

Commit

Permalink
Focusing on FromPy rather than IntoPy
Browse files Browse the repository at this point in the history
(as you get IntoPy for free)

Also try and point out that intoPy doesn't mean it's going to convert
something into a python object.
  • Loading branch information
Giles Cope committed Feb 14, 2020
1 parent 3c02de2 commit 6b4a4e8
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 6b4a4e8

Please sign in to comment.