Include conversions for bytes, bytearrays and Cow<[u8]> in the guide.

This commit is contained in:
Adam Reichold 2023-01-21 11:07:28 +01:00
parent e3e37ac624
commit a16f2e45c8
1 changed files with 3 additions and 2 deletions

View File

@ -14,7 +14,7 @@ The table below contains the Python type and the corresponding function argument
| ------------- |:-------------------------------:|:--------------------:| | ------------- |:-------------------------------:|:--------------------:|
| `object` | - | `&PyAny` | | `object` | - | `&PyAny` |
| `str` | `String`, `Cow<str>`, `&str`, `OsString`, `PathBuf` | `&PyUnicode` | | `str` | `String`, `Cow<str>`, `&str`, `OsString`, `PathBuf` | `&PyUnicode` |
| `bytes` | `Vec<u8>`, `&[u8]` | `&PyBytes` | | `bytes` | `Vec<u8>`, `&[u8]`, `Cow<[u8]>` | `&PyBytes` |
| `bool` | `bool` | `&PyBool` | | `bool` | `bool` | `&PyBool` |
| `int` | Any integer type (`i32`, `u32`, `usize`, etc) | `&PyLong` | | `int` | Any integer type (`i32`, `u32`, `usize`, etc) | `&PyLong` |
| `float` | `f32`, `f64` | `&PyFloat` | | `float` | `f32`, `f64` | `&PyFloat` |
@ -24,7 +24,7 @@ The table below contains the Python type and the corresponding function argument
| `tuple[T, U]` | `(T, U)`, `Vec<T>` | `&PyTuple` | | `tuple[T, U]` | `(T, U)`, `Vec<T>` | `&PyTuple` |
| `set[T]` | `HashSet<T>`, `BTreeSet<T>`, `hashbrown::HashSet<T>`[^2] | `&PySet` | | `set[T]` | `HashSet<T>`, `BTreeSet<T>`, `hashbrown::HashSet<T>`[^2] | `&PySet` |
| `frozenset[T]` | `HashSet<T>`, `BTreeSet<T>`, `hashbrown::HashSet<T>`[^2] | `&PyFrozenSet` | | `frozenset[T]` | `HashSet<T>`, `BTreeSet<T>`, `hashbrown::HashSet<T>`[^2] | `&PyFrozenSet` |
| `bytearray` | `Vec<u8>` | `&PyByteArray` | | `bytearray` | `Vec<u8>`, `Cow<[u8]>` | `&PyByteArray` |
| `slice` | - | `&PySlice` | | `slice` | - | `&PySlice` |
| `type` | - | `&PyType` | | `type` | - | `&PyType` |
| `module` | - | `&PyModule` | | `module` | - | `&PyModule` |
@ -84,6 +84,7 @@ Finally, the following Rust types are also able to convert to Python as return v
| `Option<T>` | `Optional[T]` | | `Option<T>` | `Optional[T]` |
| `(T, U)` | `Tuple[T, U]` | | `(T, U)` | `Tuple[T, U]` |
| `Vec<T>` | `List[T]` | | `Vec<T>` | `List[T]` |
| `Cow<[u8]>` | `bytes` |
| `HashMap<K, V>` | `Dict[K, V]` | | `HashMap<K, V>` | `Dict[K, V]` |
| `BTreeMap<K, V>` | `Dict[K, V]` | | `BTreeMap<K, V>` | `Dict[K, V]` |
| `HashSet<T>` | `Set[T]` | | `HashSet<T>` | `Set[T]` |