Skip to main content

PyMappingProxyMethods

Trait PyMappingProxyMethods 

pub trait PyMappingProxyMethods<'py, 'a>: Sealed {
    // Required methods
    fn is_empty(&self) -> Result<bool, PyErr>;
    fn keys(&self) -> Result<Bound<'py, PyList>, PyErr>;
    fn values(&self) -> Result<Bound<'py, PyList>, PyErr>;
    fn items(&self) -> Result<Bound<'py, PyList>, PyErr>;
    fn as_mapping(&self) -> &Bound<'py, PyMapping>;
    fn try_iter(&'a self) -> Result<BoundMappingProxyIterator<'py, 'a>, PyErr>;
}
Available on crate feature tls only.
Expand description

Implementation of functionality for PyMappingProxy.

These methods are defined for the Bound<'py, PyMappingProxy> 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 is_empty(&self) -> Result<bool, PyErr>

Checks if the mappingproxy is empty, i.e. len(self) == 0.

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 tuples of all (key, value) pairs in the mapping.

fn as_mapping(&self) -> &Bound<'py, PyMapping>

Returns self cast as a PyMapping.

fn try_iter(&'a self) -> Result<BoundMappingProxyIterator<'py, 'a>, PyErr>

Takes an object and returns an iterator for it. Returns an error if the object is not iterable.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

§

impl<'py, 'a> PyMappingProxyMethods<'py, 'a> for Bound<'py, PyMappingProxy>