Skip to main content

PyMappingMethods

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>;
}
Available on crate feature tls 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>

Returns the number of objects in the mapping.

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

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

Returns whether the mapping is empty.

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>,

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>,

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>,

Deletes the item with key key.

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

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

Returns a list containing all keys in the mapping.

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

Returns a list containing all values in the mapping.

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

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".

Implementors§

§

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