Skip to content

Commit 478bf77

Browse files
committed
Add concrete pointer types to the list.
1 parent c54d489 commit 478bf77

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

guide/src/types.md

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ references is done at runtime using `PyCell`, a scheme very similar to
4444
`std::cell::RefCell`.
4545

4646

47-
## Smart pointers
47+
## Object types
4848

4949
### `PyObject`
5050

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

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

9696
**Conversions:**
9797

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

100100

101+
### `PyTuple`, `PyDict`, and many more
102+
103+
**Represents:** a native Python object of known type, restricted to a GIL
104+
lifetime just like `PyAny`.
105+
106+
**Used:** Whenever you want to operate with native Python types while holding
107+
the GIL. Like `PyAny`, this is the most convenient form to use for function
108+
arguments and intermediate values.
109+
110+
**Conversions:**
111+
112+
- To `PyAny`: `obj.as_ref()`
113+
114+
101115
### `PyCell<SomeType>`
102116

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

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

111125
**Conversions:**
112126

0 commit comments

Comments
 (0)