Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write migration guide #795

Merged
merged 7 commits into from
Mar 13, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Mention let obj: T = obj.extract()?; in migration.md
  • Loading branch information
kngwyu committed Mar 9, 2020
commit a6765e3888319ac5c341ec5de2ab8a96f8e267ac
6 changes: 4 additions & 2 deletions guide/src/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ let obj_ref = obj.borrow();

#### Object extraction
For `PyClass` types `T`, `&T` and `&mut T` no longer have `FromPyObject` implementations.
Instead you should extract `PyRef<T>` or `PyRefMut<T>`, respectively. You can also extract `&PyCell<T>`.
Instead you should extract `PyRef<T>` or `PyRefMut<T>`, respectively.
If `T` implements `Clone`, you can extract `T` itself.
In addition, you can also extract `&PyCell<T>`, though you rarely need it.

Before:
```ignore
Expand All @@ -136,7 +138,7 @@ After:
# let create_obj = || py.eval("c()", None, Some(d)).unwrap();
let obj: &PyAny = create_obj();
let obj_cell: &PyCell<MyClass> = obj.extract().unwrap();
let obj_cloned: MyClass = obj.extract().unwrap(); // extracted via Clone
let obj_cloned: MyClass = obj.extract().unwrap(); // extracted by cloning the object
{
let obj_ref: PyRef<MyClass> = obj.extract().unwrap();
// we need to drop obj_ref before we can extract a PyRefMut due to Rust's rules of references
Expand Down