# Trait pyo3::prelude::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: 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§

source#### fn len(&self) -> usize

#### 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: 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`

.

source#### fn 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.

source#### fn 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.

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

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

Removes and returns an arbitrary element from the set.

source#### fn 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§

## Object Safety§

This trait is

**not**object safe.