devela::_dep::pyo3::types

Trait PySequenceMethods

pub trait PySequenceMethods<'py>: Sealed {
Show 17 methods // Required methods fn len(&self) -> Result<usize, PyErr> ; fn is_empty(&self) -> Result<bool, PyErr> ; fn concat( &self, other: &Bound<'_, PySequence>, ) -> Result<Bound<'py, PySequence>, PyErr> ; fn repeat(&self, count: usize) -> Result<Bound<'py, PySequence>, PyErr> ; fn in_place_concat( &self, other: &Bound<'_, PySequence>, ) -> Result<Bound<'py, PySequence>, PyErr> ; fn in_place_repeat( &self, count: usize, ) -> Result<Bound<'py, PySequence>, PyErr> ; fn get_item(&self, index: usize) -> Result<Bound<'py, PyAny>, PyErr> ; fn get_slice( &self, begin: usize, end: usize, ) -> Result<Bound<'py, PySequence>, PyErr> ; fn set_item<I>(&self, i: usize, item: I) -> Result<(), PyErr> where I: IntoPyObject<'py>; fn del_item(&self, i: usize) -> Result<(), PyErr> ; fn set_slice( &self, i1: usize, i2: usize, v: &Bound<'_, PyAny>, ) -> Result<(), PyErr> ; fn del_slice(&self, i1: usize, i2: usize) -> Result<(), PyErr> ; fn count<V>(&self, value: V) -> Result<usize, PyErr> where V: IntoPyObject<'py>; fn contains<V>(&self, value: V) -> Result<bool, PyErr> where V: IntoPyObject<'py>; fn index<V>(&self, value: V) -> Result<usize, PyErr> where V: IntoPyObject<'py>; fn to_list(&self) -> Result<Bound<'py, PyList>, PyErr> ; fn to_tuple(&self) -> Result<Bound<'py, PyTuple>, PyErr> ;
}
Available on crate features dep_pyo3 and std only.
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§

fn len(&self) -> Result<usize, PyErr>

Returns the number of objects in sequence.

This is equivalent to the Python expression len(self).

fn is_empty(&self) -> Result<bool, PyErr>

Returns whether the sequence is empty.

fn concat( &self, other: &Bound<'_, PySequence>, ) -> Result<Bound<'py, PySequence>, PyErr>

Returns the concatenation of self and other.

This is equivalent to the Python expression self + other.

fn repeat(&self, count: usize) -> Result<Bound<'py, PySequence>, PyErr>

Returns the result of repeating a sequence object count times.

This is equivalent to the Python expression self * count.

fn in_place_concat( &self, other: &Bound<'_, PySequence>, ) -> Result<Bound<'py, PySequence>, PyErr>

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.

fn in_place_repeat(&self, count: usize) -> Result<Bound<'py, PySequence>, PyErr>

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.

fn get_item(&self, index: usize) -> Result<Bound<'py, PyAny>, PyErr>

Returns the indexth element of the Sequence.

This is equivalent to the Python expression self[index] without support of negative indices.

fn get_slice( &self, begin: usize, end: usize, ) -> Result<Bound<'py, PySequence>, PyErr>

Returns the slice of sequence object between begin and end.

This is equivalent to the Python expression self[begin:end].

fn set_item<I>(&self, i: usize, item: I) -> Result<(), PyErr>
where I: IntoPyObject<'py>,

Assigns object item to the ith element of self.

This is equivalent to the Python statement self[i] = v.

fn del_item(&self, i: usize) -> Result<(), PyErr>

Deletes the ith element of self.

This is equivalent to the Python statement del self[i].

fn set_slice( &self, i1: usize, i2: usize, v: &Bound<'_, PyAny>, ) -> Result<(), PyErr>

Assigns the sequence v to the slice of self from i1 to i2.

This is equivalent to the Python statement self[i1:i2] = v.

fn del_slice(&self, i1: usize, i2: usize) -> Result<(), PyErr>

Deletes the slice from i1 to i2 from self.

This is equivalent to the Python statement del self[i1:i2].

fn count<V>(&self, value: V) -> Result<usize, PyErr>
where V: IntoPyObject<'py>,

Returns the number of occurrences of value in self, that is, return the number of keys for which self[key] == value.

fn contains<V>(&self, value: V) -> Result<bool, PyErr>
where V: IntoPyObject<'py>,

Determines if self contains value.

This is equivalent to the Python expression value in self.

fn index<V>(&self, value: V) -> Result<usize, PyErr>
where V: IntoPyObject<'py>,

Returns the first index i for which self[i] == value.

This is equivalent to the Python expression self.index(value).

fn to_list(&self) -> Result<Bound<'py, PyList>, PyErr>

Returns a fresh list based on the Sequence.

fn to_tuple(&self) -> Result<Bound<'py, PyTuple>, PyErr>

Returns a fresh tuple based on the Sequence.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

§

impl<'py> PySequenceMethods<'py> for Bound<'py, PySequence>