Trait pyo3::prelude::PySequenceMethods
source · pub trait PySequenceMethods<'py>: Sealed {
Show 17 methods
// Required methods
fn len(&self) -> PyResult<usize>;
fn is_empty(&self) -> PyResult<bool>;
fn concat(
&self,
other: &Bound<'_, PySequence>
) -> PyResult<Bound<'py, PySequence>>;
fn repeat(&self, count: usize) -> PyResult<Bound<'py, PySequence>>;
fn in_place_concat(
&self,
other: &Bound<'_, PySequence>
) -> PyResult<Bound<'py, PySequence>>;
fn in_place_repeat(&self, count: usize) -> PyResult<Bound<'py, PySequence>>;
fn get_item(&self, index: usize) -> PyResult<Bound<'py, PyAny>>;
fn get_slice(
&self,
begin: usize,
end: usize
) -> PyResult<Bound<'py, PySequence>>;
fn set_item<I>(&self, i: usize, item: I) -> PyResult<()>
where I: ToPyObject;
fn del_item(&self, i: usize) -> PyResult<()>;
fn set_slice(
&self,
i1: usize,
i2: usize,
v: &Bound<'_, PyAny>
) -> PyResult<()>;
fn del_slice(&self, i1: usize, i2: usize) -> PyResult<()>;
fn count<V>(&self, value: V) -> PyResult<usize>
where V: ToPyObject;
fn contains<V>(&self, value: V) -> PyResult<bool>
where V: ToPyObject;
fn index<V>(&self, value: V) -> PyResult<usize>
where V: ToPyObject;
fn to_list(&self) -> PyResult<Bound<'py, PyList>>;
fn to_tuple(&self) -> PyResult<Bound<'py, PyTuple>>;
}
Expand description
Implementation of functionality for PySequence
.
These methods are defined for the Bound<'py, PySequence>
smart pointer, so to use method call
syntax these methods are separated into a trait, because stable Rust does not yet support
arbitrary_self_types
.
Required Methods§
sourcefn len(&self) -> PyResult<usize>
fn len(&self) -> PyResult<usize>
Returns the number of objects in sequence.
This is equivalent to the Python expression len(self)
.
sourcefn concat(
&self,
other: &Bound<'_, PySequence>
) -> PyResult<Bound<'py, PySequence>>
fn concat( &self, other: &Bound<'_, PySequence> ) -> PyResult<Bound<'py, PySequence>>
Returns the concatenation of self
and other
.
This is equivalent to the Python expression self + other
.
sourcefn repeat(&self, count: usize) -> PyResult<Bound<'py, PySequence>>
fn repeat(&self, count: usize) -> PyResult<Bound<'py, PySequence>>
Returns the result of repeating a sequence object count
times.
This is equivalent to the Python expression self * count
.
sourcefn in_place_concat(
&self,
other: &Bound<'_, PySequence>
) -> PyResult<Bound<'py, PySequence>>
fn in_place_concat( &self, other: &Bound<'_, PySequence> ) -> PyResult<Bound<'py, PySequence>>
Concatenates self
and other
, in place if possible.
This is equivalent to the Python expression self.__iadd__(other)
.
The Python statement self += other
is syntactic sugar for self = self.__iadd__(other)
. __iadd__
should modify and return self
if
possible, but create and return a new object if not.
sourcefn in_place_repeat(&self, count: usize) -> PyResult<Bound<'py, PySequence>>
fn in_place_repeat(&self, count: usize) -> PyResult<Bound<'py, PySequence>>
Repeats the sequence object count
times and updates self
, if possible.
This is equivalent to the Python expression self.__imul__(other)
.
The Python statement self *= other
is syntactic sugar for self = self.__imul__(other)
. __imul__
should modify and return self
if
possible, but create and return a new object if not.
sourcefn get_item(&self, index: usize) -> PyResult<Bound<'py, PyAny>>
fn get_item(&self, index: usize) -> PyResult<Bound<'py, PyAny>>
Returns the index
th element of the Sequence.
This is equivalent to the Python expression self[index]
without support of negative indices.
sourcefn get_slice(
&self,
begin: usize,
end: usize
) -> PyResult<Bound<'py, PySequence>>
fn get_slice( &self, begin: usize, end: usize ) -> PyResult<Bound<'py, PySequence>>
Returns the slice of sequence object between begin
and end
.
This is equivalent to the Python expression self[begin:end]
.
sourcefn set_item<I>(&self, i: usize, item: I) -> PyResult<()>where
I: ToPyObject,
fn set_item<I>(&self, i: usize, item: I) -> PyResult<()>where
I: ToPyObject,
Assigns object item
to the i
th element of self.
This is equivalent to the Python statement self[i] = v
.
sourcefn del_item(&self, i: usize) -> PyResult<()>
fn del_item(&self, i: usize) -> PyResult<()>
Deletes the i
th element of self.
This is equivalent to the Python statement del self[i]
.
sourcefn set_slice(&self, i1: usize, i2: usize, v: &Bound<'_, PyAny>) -> PyResult<()>
fn set_slice(&self, i1: usize, i2: usize, v: &Bound<'_, PyAny>) -> PyResult<()>
Assigns the sequence v
to the slice of self
from i1
to i2
.
This is equivalent to the Python statement self[i1:i2] = v
.
sourcefn del_slice(&self, i1: usize, i2: usize) -> PyResult<()>
fn del_slice(&self, i1: usize, i2: usize) -> PyResult<()>
Deletes the slice from i1
to i2
from self
.
This is equivalent to the Python statement del self[i1:i2]
.
sourcefn count<V>(&self, value: V) -> PyResult<usize>where
V: ToPyObject,
Available on non-PyPy
only.
fn count<V>(&self, value: V) -> PyResult<usize>where
V: ToPyObject,
PyPy
only.Returns the number of occurrences of value
in self, that is, return the
number of keys for which self[key] == value
.
sourcefn contains<V>(&self, value: V) -> PyResult<bool>where
V: ToPyObject,
fn contains<V>(&self, value: V) -> PyResult<bool>where
V: ToPyObject,
Determines if self contains value
.
This is equivalent to the Python expression value in self
.
sourcefn index<V>(&self, value: V) -> PyResult<usize>where
V: ToPyObject,
fn index<V>(&self, value: V) -> PyResult<usize>where
V: ToPyObject,
Returns the first index i
for which self[i] == value
.
This is equivalent to the Python expression self.index(value)
.