Trait PyMappingMethods
pub trait PyMappingMethods<'py>: Sealed {
// Required methods
fn len(&self) -> Result<usize, PyErr> ⓘ;
fn is_empty(&self) -> Result<bool, PyErr> ⓘ;
fn contains<K>(&self, key: K) -> Result<bool, PyErr> ⓘ
where K: IntoPyObject<'py>;
fn get_item<K>(&self, key: K) -> Result<Bound<'py, PyAny>, PyErr> ⓘ
where K: IntoPyObject<'py>;
fn set_item<K, V>(&self, key: K, value: V) -> Result<(), PyErr> ⓘ
where K: IntoPyObject<'py>,
V: IntoPyObject<'py>;
fn del_item<K>(&self, key: K) -> Result<(), PyErr> ⓘ
where K: IntoPyObject<'py>;
fn keys(&self) -> Result<Bound<'py, PyList>, PyErr> ⓘ;
fn values(&self) -> Result<Bound<'py, PyList>, PyErr> ⓘ;
fn items(&self) -> Result<Bound<'py, PyList>, PyErr> ⓘ;
}
dep_pyo3
and std
only.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§
fn len(&self) -> Result<usize, PyErr> ⓘ
fn len(&self) -> Result<usize, PyErr> ⓘ
Returns the number of objects in the mapping.
This is equivalent to the Python expression len(self)
.
fn contains<K>(&self, key: K) -> Result<bool, PyErr> ⓘwhere
K: IntoPyObject<'py>,
fn contains<K>(&self, key: K) -> Result<bool, PyErr> ⓘwhere
K: IntoPyObject<'py>,
Determines if the mapping contains the specified key.
This is equivalent to the Python expression key in self
.
fn get_item<K>(&self, key: K) -> Result<Bound<'py, PyAny>, PyErr> ⓘwhere
K: IntoPyObject<'py>,
fn get_item<K>(&self, key: K) -> Result<Bound<'py, PyAny>, PyErr> ⓘwhere
K: IntoPyObject<'py>,
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]
.
fn set_item<K, V>(&self, key: K, value: V) -> Result<(), PyErr> ⓘwhere
K: IntoPyObject<'py>,
V: IntoPyObject<'py>,
fn set_item<K, V>(&self, key: K, value: V) -> Result<(), PyErr> ⓘwhere
K: IntoPyObject<'py>,
V: IntoPyObject<'py>,
Sets the item in self with key key
.
This is equivalent to the Python expression self[key] = value
.
fn del_item<K>(&self, key: K) -> Result<(), PyErr> ⓘwhere
K: IntoPyObject<'py>,
fn del_item<K>(&self, key: K) -> Result<(), PyErr> ⓘwhere
K: IntoPyObject<'py>,
Deletes the item with key key
.
This is equivalent to the Python statement del self[key]
.
fn keys(&self) -> Result<Bound<'py, PyList>, PyErr> ⓘ
fn keys(&self) -> Result<Bound<'py, PyList>, PyErr> ⓘ
Returns a list containing all keys in the mapping.
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.