devela::_dep::pyo3::types

Trait PySetMethods

pub trait PySetMethods<'py>: Sealed {
    // Required methods
    fn clear(&self);
    fn len(&self) -> usize ;
    fn contains<K>(&self, key: K) -> Result<bool, PyErr> 
       where K: IntoPyObject<'py>;
    fn discard<K>(&self, key: K) -> Result<bool, PyErr> 
       where K: IntoPyObject<'py>;
    fn add<K>(&self, key: K) -> Result<(), PyErr> 
       where K: IntoPyObject<'py>;
    fn pop(&self) -> Option<Bound<'py, PyAny>> ;
    fn iter(&self) -> BoundSetIterator<'py> ;

    // Provided method
    fn is_empty(&self) -> bool { ... }
}
Available on crate features dep_pyo3 and std only.
Expand description

Implementation of functionality for PySet.

These methods are defined for the Bound<'py, PySet> 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 clear(&self)

Removes all elements from the set.

fn len(&self) -> usize

Returns the number of items in the set.

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

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

Determines if the set contains the specified key.

This is equivalent to the Python expression key in self.

fn discard<K>(&self, key: K) -> Result<bool, PyErr>
where K: IntoPyObject<'py>,

Removes the element from the set if it is present.

Returns true if the element was present in the set.

fn add<K>(&self, key: K) -> Result<(), PyErr>
where K: IntoPyObject<'py>,

Adds an element to the set.

fn pop(&self) -> Option<Bound<'py, PyAny>>

Removes and returns an arbitrary element from the set.

fn iter(&self) -> BoundSetIterator<'py>

Returns an iterator of values in this set.

§Panics

If PyO3 detects that the set is mutated during iteration, it will panic.

Provided Methods§

fn is_empty(&self) -> bool

Checks if set is empty.

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§

§

impl<'py> PySetMethods<'py> for Bound<'py, PySet>