pyo3/conversions/std/
vec.rs

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