pub trait PySetMethods<'py>: Sealed {
// Required methods
fn clear(&self);
fn len(&self) -> usize;
fn contains<K>(&self, key: K) -> PyResult<bool>
where K: ToPyObject;
fn discard<K>(&self, key: K) -> PyResult<bool>
where K: ToPyObject;
fn add<K>(&self, key: K) -> PyResult<()>
where K: ToPyObject;
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§
Sourcefn len(&self) -> usize
fn len(&self) -> usize
Returns the number of items in the set.
This is equivalent to the Python expression len(self)
.
Sourcefn contains<K>(&self, key: K) -> PyResult<bool>where
K: ToPyObject,
fn contains<K>(&self, key: K) -> PyResult<bool>where
K: ToPyObject,
Determines if the set contains the specified key.
This is equivalent to the Python expression key in self
.
Sourcefn discard<K>(&self, key: K) -> PyResult<bool>where
K: ToPyObject,
fn discard<K>(&self, key: K) -> PyResult<bool>where
K: ToPyObject,
Removes the element from the set if it is present.
Returns true
if the element was present in the set.
Sourcefn add<K>(&self, key: K) -> PyResult<()>where
K: ToPyObject,
fn add<K>(&self, key: K) -> PyResult<()>where
K: ToPyObject,
Adds an element to the set.
Sourcefn pop(&self) -> Option<Bound<'py, PyAny>>
fn pop(&self) -> Option<Bound<'py, PyAny>>
Removes and returns an arbitrary element from the set.
Sourcefn iter(&self) -> BoundSetIterator<'py> ⓘ
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§
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.