pyo3::types::mapping

Trait 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: IntoPyObject<'py>;
    fn get_item<K>(&self, key: K) -> PyResult<Bound<'py, PyAny>>
       where K: IntoPyObject<'py>;
    fn set_item<K, V>(&self, key: K, value: V) -> PyResult<()>
       where K: IntoPyObject<'py>,
             V: IntoPyObject<'py>;
    fn del_item<K>(&self, key: K) -> PyResult<()>
       where K: IntoPyObject<'py>;
    fn keys(&self) -> PyResult<Bound<'py, PyList>>;
    fn values(&self) -> PyResult<Bound<'py, PyList>>;
    fn items(&self) -> PyResult<Bound<'py, PyList>>;
}
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§

Source

fn len(&self) -> PyResult<usize>

Returns the number of objects in the mapping.

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

Source

fn is_empty(&self) -> PyResult<bool>

Returns whether the mapping is empty.

Source

fn contains<K>(&self, key: K) -> PyResult<bool>
where K: IntoPyObject<'py>,

Determines if the mapping contains the specified key.

This is equivalent to the Python expression key in self.

Source

fn get_item<K>(&self, key: K) -> PyResult<Bound<'py, PyAny>>
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].

Source

fn set_item<K, V>(&self, key: K, value: V) -> PyResult<()>
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.

Source

fn del_item<K>(&self, key: K) -> PyResult<()>
where K: IntoPyObject<'py>,

Deletes the item with key key.

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

Source

fn keys(&self) -> PyResult<Bound<'py, PyList>>

Returns a list containing all keys in the mapping.

Source

fn values(&self) -> PyResult<Bound<'py, PyList>>

Returns a list containing all values in the mapping.

Source

fn items(&self) -> PyResult<Bound<'py, PyList>>

Returns a list of all (key, value) pairs 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.

Implementors§

Source§

impl<'py> PyMappingMethods<'py> for Bound<'py, PyMapping>

⚠️ Internal Docs ⚠️ Not Public API 👉 Official Docs Here