Struct cpython::PySequence
source · pub struct PySequence(/* private fields */);
Expand description
Represents a reference to a python object supporting the sequence protocol.
Implementations§
source§impl PySequence
impl PySequence
sourcepub fn len(&self, py: Python<'_>) -> PyResult<isize>
pub fn len(&self, py: Python<'_>) -> PyResult<isize>
Returns the number of objects in sequence. This is equivalent to Python len()
.
sourcepub fn concat(&self, py: Python<'_>, other: &PySequence) -> PyResult<PyObject>
pub fn concat(&self, py: Python<'_>, other: &PySequence) -> PyResult<PyObject>
Return the concatenation of o1 and o2. Equivalent to python o1 + o2
sourcepub fn repeat(&self, py: Python<'_>, count: isize) -> PyResult<PyObject>
pub fn repeat(&self, py: Python<'_>, count: isize) -> PyResult<PyObject>
Return the result of repeating sequence object o count times.
Equivalent to python o * count
NB: Python accepts negative counts; it returns an empty Sequence.
sourcepub fn in_place_concat(
&self,
py: Python<'_>,
other: &PySequence
) -> PyResult<PyObject>
pub fn in_place_concat( &self, py: Python<'_>, other: &PySequence ) -> PyResult<PyObject>
Return the concatenation of o1 and o2 on success. Equivalent to python o1 += o2
sourcepub fn in_place_repeat(
&self,
py: Python<'_>,
count: isize
) -> PyResult<PyObject>
pub fn in_place_repeat( &self, py: Python<'_>, count: isize ) -> PyResult<PyObject>
Return the result of repeating sequence object o count times.
Equivalent to python o *= count
NB: Python accepts negative counts; it empties the Sequence.
sourcepub fn get_item(&self, py: Python<'_>, index: isize) -> PyResult<PyObject>
pub fn get_item(&self, py: Python<'_>, index: isize) -> PyResult<PyObject>
Return the ith element of the Sequence. Equivalent to python o[index]
sourcepub fn get_slice(
&self,
py: Python<'_>,
begin: isize,
end: isize
) -> PyResult<PyObject>
pub fn get_slice( &self, py: Python<'_>, begin: isize, end: isize ) -> PyResult<PyObject>
Return the slice of sequence object o between begin and end.
This is the equivalent of the Python expression o[begin:end]
sourcepub fn set_item(&self, py: Python<'_>, i: isize, v: &PyObject) -> PyResult<()>
pub fn set_item(&self, py: Python<'_>, i: isize, v: &PyObject) -> PyResult<()>
Assign object v to the ith element of o.
Equivalent to Python statement o[i] = v
sourcepub fn del_item(&self, py: Python<'_>, i: isize) -> PyResult<()>
pub fn del_item(&self, py: Python<'_>, i: isize) -> PyResult<()>
Delete the ith element of object o.
Python statement del o[i]
sourcepub fn set_slice(
&self,
py: Python<'_>,
i1: isize,
i2: isize,
v: &PyObject
) -> PyResult<()>
pub fn set_slice( &self, py: Python<'_>, i1: isize, i2: isize, v: &PyObject ) -> PyResult<()>
Assign the sequence object v to the slice in sequence object o from i1 to i2.
This is the equivalent of the Python statement o[i1:i2] = v
sourcepub fn del_slice(&self, py: Python<'_>, i1: isize, i2: isize) -> PyResult<()>
pub fn del_slice(&self, py: Python<'_>, i1: isize, i2: isize) -> PyResult<()>
Delete the slice in sequence object o from i1 to i2.
equivalent of the Python statement del o[i1:i2]
sourcepub fn count<V>(&self, py: Python<'_>, value: V) -> PyResult<usize>where
V: ToPyObject,
pub fn count<V>(&self, py: Python<'_>, value: V) -> PyResult<usize>where
V: ToPyObject,
Return the number of occurrences of value in o, that is, return the number of keys for
which o[key] == value
sourcepub fn contains<V>(&self, py: Python<'_>, value: V) -> PyResult<bool>where
V: ToPyObject,
pub fn contains<V>(&self, py: Python<'_>, value: V) -> PyResult<bool>where
V: ToPyObject,
Determine if o contains value. this is equivalent to the Python expression value in o
sourcepub fn index<V>(&self, py: Python<'_>, value: V) -> PyResult<usize>where
V: ToPyObject,
pub fn index<V>(&self, py: Python<'_>, value: V) -> PyResult<usize>where
V: ToPyObject,
Return the first index i for which o[i] == value.
This is equivalent to the Python expression o.index(value)
sourcepub fn list(&self, py: Python<'_>) -> PyResult<PyList>
pub fn list(&self, py: Python<'_>) -> PyResult<PyList>
Return a fresh list based on the Sequence.
sourcepub fn tuple(&self, py: Python<'_>) -> PyResult<PyTuple>
pub fn tuple(&self, py: Python<'_>) -> PyResult<PyTuple>
Return a fresh tuple based on the Sequence.
pub fn iter<'p>(&self, py: Python<'p>) -> PyResult<PyIterator<'p>>
Trait Implementations§
source§impl<'s> FromPyObject<'s> for &'s PySequence
impl<'s> FromPyObject<'s> for &'s PySequence
source§impl<'s> FromPyObject<'s> for PySequence
impl<'s> FromPyObject<'s> for PySequence
source§impl PythonObject for PySequence
impl PythonObject for PySequence
source§unsafe fn unchecked_downcast_from(obj: PyObject) -> Self
unsafe fn unchecked_downcast_from(obj: PyObject) -> Self
Unchecked downcast from PyObject to Self. Undefined behavior if the input object does not have the expected type.
source§unsafe fn unchecked_downcast_borrow_from<'a>(obj: &'a PyObject) -> &'a Self
unsafe fn unchecked_downcast_borrow_from<'a>(obj: &'a PyObject) -> &'a Self
Unchecked downcast from PyObject to Self. Undefined behavior if the input object does not have the expected type.
source§fn into_object(self) -> PyObject
fn into_object(self) -> PyObject
source§impl PythonObjectWithCheckedDowncast for PySequence
impl PythonObjectWithCheckedDowncast for PySequence
source§fn downcast_from<'p>(
py: Python<'p>,
obj: PyObject
) -> Result<PySequence, PythonObjectDowncastError<'p>>
fn downcast_from<'p>( py: Python<'p>, obj: PyObject ) -> Result<PySequence, PythonObjectDowncastError<'p>>
source§fn downcast_borrow_from<'a, 'p>(
py: Python<'p>,
obj: &'a PyObject
) -> Result<&'a PySequence, PythonObjectDowncastError<'p>>
fn downcast_borrow_from<'a, 'p>( py: Python<'p>, obj: &'a PyObject ) -> Result<&'a PySequence, PythonObjectDowncastError<'p>>
source§impl ToPyObject for PySequence
impl ToPyObject for PySequence
Identity conversion: allows using existing PyObject
instances where
T: ToPyObject
is expected.