Skip to content

Commit

Permalink
Add concrete pointer types to the list.
Browse files Browse the repository at this point in the history
  • Loading branch information
birkenfeld committed Mar 13, 2020
1 parent 652f264 commit 2d2d26a
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions guide/src/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ references is done at runtime using `PyCell`, a scheme very similar to
`std::cell::RefCell`.


## Smart pointers
## Object types

### `PyObject`

Expand Down Expand Up @@ -90,23 +90,37 @@ lifetime. Currently, `PyAny` can only ever occur as a reference, e.g. `&PyAny`
or `PyRef<PyAny>`.

**Used:** Whenever you want to refer to some Python object only as long as
holding the GIL. For example, arguments to `pyfunction`s or `pymethod`s
implemented in Rust where any type is allowed.
holding the GIL. For example, intermediate values and arguments to
`pyfunction`s or `pymethod`s implemented in Rust where any type is allowed.

**Conversions:**

- To `PyObject`: `obj.to_object(py)`


### `PyTuple`, `PyDict`, and many more

**Represents:** a native Python object of known type, restricted to a GIL
lifetime just like `PyAny`.

**Used:** Whenever you want to operate with native Python types while holding
the GIL. Like `PyAny`, this is the most convenient form to use for function
arguments and intermediate values.

**Conversions:**

- To `PyAny`: `obj.as_ref()`


### `PyCell<SomeType>`

**Represents:** a reference to a `PyClass` instance which is wrapped in a Python
object. The cell part is an analog to stdlib's [`RefCell`][RefCell] to allow access to
`&mut` references.
**Represents:** a reference to a Rust object (instance of `PyClass`) which is
wrapped in a Python object. The cell part is an analog to stdlib's
[`RefCell`][RefCell] to allow access to `&mut` references.

**Used:** for accessing pure-Rust API of the instance (members and functions
taking `&SomeType` or `&mut SomeType`) while maintaining the aliasing rules
of Rust references.
taking `&SomeType` or `&mut SomeType`) while maintaining the aliasing rules of
Rust references.

**Conversions:**

Expand Down

0 comments on commit 2d2d26a

Please sign in to comment.