From 6b4a4e881a7e90053bee8f499f8a08b239f11ca7 Mon Sep 17 00:00:00 2001 From: Giles Cope Date: Fri, 14 Feb 2020 06:35:41 +0000 Subject: [PATCH] Focusing on FromPy rather than IntoPy (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. --- guide/src/conversions.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/guide/src/conversions.md b/guide/src/conversions.md index 2f388c9f..ed6f3e01 100644 --- a/guide/src/conversions.md +++ b/guide/src/conversions.md @@ -100,9 +100,11 @@ fn main() { } ``` -## `IntoPy` +## `FromPy` and `IntoPy` -Many conversions in PyO3 can't use `std::convert::Into` because they need a GIL token. That's why the `IntoPy` 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` trait offers an `from_py` method that works just like `from`, except for taking a `Python<'_>` argument. I.e. FromPy 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, if you implement FromPy you gain a blanket implementation of IntoPy 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`.