pub struct PyList(/* private fields */);
Expand description
Represents a Python list
.
Values of this type are accessed via PyO3’s smart pointers, e.g. as
Py<PyList>
or Bound<'py, PyList>
.
For APIs available on list
objects, see the PyListMethods
trait which is implemented for
Bound<'py, PyDict>
.
Implementations§
Source§impl PyList
impl PyList
Sourcepub fn new_bound<T, U>(
py: Python<'_>,
elements: impl IntoIterator<Item = T, IntoIter = U>,
) -> Bound<'_, PyList>where
T: ToPyObject,
U: ExactSizeIterator<Item = T>,
pub fn new_bound<T, U>(
py: Python<'_>,
elements: impl IntoIterator<Item = T, IntoIter = U>,
) -> Bound<'_, PyList>where
T: ToPyObject,
U: ExactSizeIterator<Item = T>,
Constructs a new list with the given elements.
If you want to create a PyList
with elements of different or unknown types, or from an
iterable that doesn’t implement ExactSizeIterator
, use PyListMethods::append
.
§Examples
use pyo3::prelude::*;
use pyo3::types::PyList;
Python::with_gil(|py| {
let elements: Vec<i32> = vec![0, 1, 2, 3, 4, 5];
let list = PyList::new_bound(py, elements);
assert_eq!(format!("{:?}", list), "[0, 1, 2, 3, 4, 5]");
});
§Panics
This function will panic if element
’s ExactSizeIterator
implementation is incorrect.
All standard library structures implement this trait correctly, if they do, so calling this
function with (for example) Vec
<T>
or &[T]
will always succeed.
Sourcepub fn empty_bound(py: Python<'_>) -> Bound<'_, PyList>
pub fn empty_bound(py: Python<'_>) -> Bound<'_, PyList>
Constructs a new empty list.
Trait Implementations§
Source§impl AsPyPointer for PyList
impl AsPyPointer for PyList
Source§impl PyTypeInfo for PyList
impl PyTypeInfo for PyList
Source§fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
Returns the PyTypeObject instance for this type.
Source§fn is_type_of_bound(obj: &Bound<'_, PyAny>) -> bool
fn is_type_of_bound(obj: &Bound<'_, PyAny>) -> bool
Checks if
object
is an instance of this type or a subclass of this type.impl DerefToPyAny for PyList
Auto Trait Implementations§
impl !Freeze for PyList
impl !RefUnwindSafe for PyList
impl !Send for PyList
impl !Sync for PyList
impl Unpin for PyList
impl UnwindSafe for PyList
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more