Skip to main content

PySetMethods

Trait PySetMethods 

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

    // Provided method
    fn is_empty(&self) -> bool { ... }
}
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§

Source

fn clear(&self)

Removes all elements from the set.

Source

fn len(&self) -> usize

Returns the number of items in the set.

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

Source

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

Determines if the set contains the specified key.

This is equivalent to the Python expression key in self.

Source

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

Removes the element from the set if it is present.

Returns true if the element was present in the set.

Source

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

Adds an element to the set.

Source

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

Removes and returns an arbitrary element from the set.

Source

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§

Source

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

Implementors§

Source§

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