Update conversions chapter

This commit is contained in:
messense 2017-06-25 19:31:32 +08:00
parent 2d217be349
commit a00e23a594
No known key found for this signature in database
GPG key ID: BB41A8A2C716CCA9

View file

@ -4,14 +4,32 @@
## `ToPyObject` and `IntoPyObject` trait
`ToPyObject` trait is a conversion trait that allows various objects to be converted into `PyObject`.
TODO
[`ToPyObject`][ToPyObject] trait is a conversion trait that allows various objects to be converted into [`PyObject`][PyObject]. [`IntoPyObject`][IntoPyObject] serves the same purpose except it consumes `self`.
## `IntoPyTuple` trait
TODO
[`IntoPyTuple`][IntoPyTuple] trait is a conversion trait that allows various objects to be converted into [`PyTuple`][PyTuple] object.
For example, [`IntoPyTuple`][IntoPyTuple] trait is implemented for `()` so that you can convert it into a empty [`PyTuple`][PyTuple]
```rust
extern crate pyo3;
use pyo3::{Python, IntoPyTuple};
fn main() {
let gil = Python::acquire_gil();
let py = gil.python();
let py_tuple = ().into_tuple(py);
}
```
## `FromPyObject` and `RefFromPyObject` trait
TODO
[ToPyObject]: https://pyo3.github.io/PyO3/pyo3/trait.ToPyObject.html
[IntoPyObject]: https://pyo3.github.io/PyO3/pyo3/trait.IntoPyObject.html
[PyObject]: https://pyo3.github.io/PyO3/pyo3/struct.PyObject.html
[IntoPyTuple]: https://pyo3.github.io/PyO3/pyo3/trait.IntoPyTuple.html
[PyTuple]: https://pyo3.github.io/PyO3/pyo3/struct.PyTuple.html