Apply suggestions from code review

Co-Authored-By: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
This commit is contained in:
Yuji Kanagawa 2020-03-01 12:43:04 +09:00 committed by GitHub
parent 461b32a432
commit 399e4bf9b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 5 deletions

View File

@ -16,10 +16,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
* The implementation for `IntoPy<U> for T` where `U: FromPy<T>` is no longer specializable. Control the behavior of this via the implementation of `FromPy`. [#713](https://github.com/PyO3/pyo3/pull/713)
* Use `parking_lot::Mutex` instead of `spin::Mutex`. [#734](https://github.com/PyO3/pyo3/pull/734)
* Bumped minimum Rust version to `1.42.0-nightly 2020-01-21`. [#761](https://github.com/PyO3/pyo3/pull/761)
* `PyClassShell` is renamed `PyCell` and has RefCell-like features. [#770](https://github.com/PyO3/pyo3/pull/770)
### Added
* `PyCell`, which has RefCell-like features. [#770](https://github.com/PyO3/pyo3/pull/770)
* `PyClass`, `PyClassShell`, `PyObjectLayout`, `PyClassInitializer`. [#683](https://github.com/PyO3/pyo3/pull/683)
* Implemented `IntoIterator` for `PySet` and `PyFrozenSet`. [#716](https://github.com/PyO3/pyo3/pull/716)
* `FromPyObject` is now automatically implemented for `T: Clone` pyclasses. [#730](https://github.com/PyO3/pyo3/pull/730)

View File

@ -122,7 +122,7 @@ like [std::cell::RefCell](https://doc.rust-lang.org/std/cell/struct.RefCell.html
Users who are familiar with `RefCell` can use `PyCell` just like `RefCell`.
For users who doesn't know `RefCell` well, here we repeat the Rust's borrowing rule:
For users who are not very familiar with `RefCell`, here is a reminder of Rust's rules of borrowing:
- At any given time, you can have either (but not both of) one mutable reference or any number of immutable references.
- References must always be valid.
`PyCell` ensures these borrowing rules by tracking references at runtime.
@ -156,7 +156,7 @@ let obj = PyCell::new(py, MyClass { num: 3, debug: true }).unwrap();
pyo3::py_run!(py, obj, "assert obj.num == 5")
```
`&PyCell<T>` is bouded by the same lifetime as `GILGuard`.
`&PyCell<T>` is bounded by the same lifetime as `GILGuard`.
To avoid this you can use `Py<T>`, which stores an object longer than the GIL lifetime.
```rust
# use pyo3::prelude::*;

View File

@ -33,7 +33,7 @@ pub trait PySizedLayout<T: PyTypeInfo>: PyLayout<T> + Sized {}
///
/// # Safety
///
/// Self should be layouted as follows:
/// Self should be laid out as follows:
/// ```ignore
/// #[repr(C)]
/// struct Self {