Skip to content

Commit

Permalink
Apply suggestions from davidhewitt's review
Browse files Browse the repository at this point in the history
Co-Authored-By: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
  • Loading branch information
kngwyu and davidhewitt authored Feb 18, 2020
1 parent daca04e commit 1da2601
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions guide/src/class.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ from Rust code (e.g., for testing it).
`PyCell<T: PyClass>` is always allocated in the Python heap, so we don't have the ownership of it.
We can get `&PyCell<T>`, not `PyCell<T>`.

Thus, to mutate data behind `&PyCell` safely, we employs
Thus, to mutate data behind `&PyCell` safely, we employ the
[Interior Mutability Pattern](https://doc.rust-lang.org/book/ch15-05-interior-mutability.html)
like [std::cell::RefCell](https://doc.rust-lang.org/std/cell/struct.RefCell.html).

Expand Down Expand Up @@ -145,13 +145,13 @@ let obj = PyCell::new(py, MyClass { num: 3, debug: true }).unwrap();
{
let obj_ref = obj.borrow(); // Get PyRef
assert_eq!(obj_ref.num, 3);
// You cannot get PyRefMut unless all PyRef drop
// You cannot get PyRefMut unless all PyRefs are dropped
assert!(obj.try_borrow_mut().is_err());
}
{
let mut obj_mut = obj.borrow_mut(); // Get PyRefMut
obj_mut.num = 5;
// You cannot get PyRef unless all PyRefMut drop
// You cannot get any other refs until the PyRefMut is dropped
assert!(obj.try_borrow().is_err());
}
// You can convert `&PyCell` to Python object
Expand Down
2 changes: 1 addition & 1 deletion pyo3-derive-backend/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub fn process_functions_in_module(func: &mut syn::ItemFn) {
fn wrap_fn_argument<'a>(cap: &'a syn::PatType, name: &'a Ident) -> method::FnArg<'a> {
let (mutability, by_ref, ident) = match *cap.pat {
syn::Pat::Ident(ref patid) => (&patid.mutability, &patid.by_ref, &patid.ident),
_ => panic!("unsupported argument: {:?}", cap.pat),
_ => return syn::Error::new_spanned(cap.pat, "Unsupported argument"),
};

let py = crate::utils::if_type_is_python(&cap.ty);
Expand Down

0 comments on commit 1da2601

Please sign in to comment.