Trait pyo3::prelude::PyMappingMethods
source · pub trait PyMappingMethods<'py>: Sealed {
// Required methods
fn len(&self) -> PyResult<usize>;
fn is_empty(&self) -> PyResult<bool>;
fn contains<K>(&self, key: K) -> PyResult<bool>
where K: ToPyObject;
fn get_item<K>(&self, key: K) -> PyResult<Bound<'py, PyAny>>
where K: ToPyObject;
fn set_item<K, V>(&self, key: K, value: V) -> PyResult<()>
where K: ToPyObject,
V: ToPyObject;
fn del_item<K>(&self, key: K) -> PyResult<()>
where K: ToPyObject;
fn keys(&self) -> PyResult<Bound<'py, PySequence>>;
fn values(&self) -> PyResult<Bound<'py, PySequence>>;
fn items(&self) -> PyResult<Bound<'py, PySequence>>;
}
Expand description
Implementation of functionality for PyMapping
.
These methods are defined for the Bound<'py, PyMapping>
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 the mapping.
This is equivalent to the Python expression len(self)
.
sourcefn contains<K>(&self, key: K) -> PyResult<bool>where
K: ToPyObject,
fn contains<K>(&self, key: K) -> PyResult<bool>where
K: ToPyObject,
Determines if the mapping contains the specified key.
This is equivalent to the Python expression key in self
.
sourcefn get_item<K>(&self, key: K) -> PyResult<Bound<'py, PyAny>>where
K: ToPyObject,
fn get_item<K>(&self, key: K) -> PyResult<Bound<'py, PyAny>>where
K: ToPyObject,
Gets the item in self with key key
.
Returns an Err
if the item with specified key is not found, usually KeyError
.
This is equivalent to the Python expression self[key]
.
sourcefn set_item<K, V>(&self, key: K, value: V) -> PyResult<()>where
K: ToPyObject,
V: ToPyObject,
fn set_item<K, V>(&self, key: K, value: V) -> PyResult<()>where
K: ToPyObject,
V: ToPyObject,
Sets the item in self with key key
.
This is equivalent to the Python expression self[key] = value
.
sourcefn del_item<K>(&self, key: K) -> PyResult<()>where
K: ToPyObject,
fn del_item<K>(&self, key: K) -> PyResult<()>where
K: ToPyObject,
Deletes the item with key key
.
This is equivalent to the Python statement del self[key]
.
sourcefn keys(&self) -> PyResult<Bound<'py, PySequence>>
fn keys(&self) -> PyResult<Bound<'py, PySequence>>
Returns a sequence containing all keys in the mapping.
sourcefn values(&self) -> PyResult<Bound<'py, PySequence>>
fn values(&self) -> PyResult<Bound<'py, PySequence>>
Returns a sequence containing all values in the mapping.
sourcefn items(&self) -> PyResult<Bound<'py, PySequence>>
fn items(&self) -> PyResult<Bound<'py, PySequence>>
Returns a sequence of tuples of all (key, value) pairs in the mapping.