1 | #[cfg (feature = "experimental-inspect" )] |
2 | use crate::inspect::types::TypeInfo; |
3 | use crate::types::list::new_from_iter; |
4 | use crate::{IntoPy, PyObject, Python, ToPyObject}; |
5 | |
6 | impl<T> ToPyObject for [T] |
7 | where |
8 | T: ToPyObject, |
9 | { |
10 | fn to_object(&self, py: Python<'_>) -> PyObject { |
11 | let mut iter: impl Iterator- >
= self.iter().map(|e: &T| e.to_object(py)); |
12 | let list: Py = new_from_iter(py, &mut iter); |
13 | list.into() |
14 | } |
15 | } |
16 | |
17 | impl<T> ToPyObject for Vec<T> |
18 | where |
19 | T: ToPyObject, |
20 | { |
21 | fn to_object(&self, py: Python<'_>) -> PyObject { |
22 | self.as_slice().to_object(py) |
23 | } |
24 | } |
25 | |
26 | impl<T> IntoPy<PyObject> for Vec<T> |
27 | where |
28 | T: IntoPy<PyObject>, |
29 | { |
30 | fn into_py(self, py: Python<'_>) -> PyObject { |
31 | let mut iter: impl Iterator- >
= self.into_iter().map(|e: T| e.into_py(py)); |
32 | let list: Py = new_from_iter(py, &mut iter); |
33 | list.into() |
34 | } |
35 | |
36 | #[cfg (feature = "experimental-inspect" )] |
37 | fn type_output() -> TypeInfo { |
38 | TypeInfo::list_of(T::type_output()) |
39 | } |
40 | } |
41 | |