# CompositeDisposable

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-reactive/disposables/struct-compositedisposable/

**struct** · [`ferroui-reactive`](/docs/0.5.0/api/ferroui-reactive/) · v0.5.0

```rust
struct CompositeDisposable
```

A group of disposables that are disposed together (`CompositeDisposable`).

Disposables compare by identity (`Remove`, `Contains`); a disposable added twice is held twice.
A disposable added after the group was disposed is disposed at once. The group disposes its
members outside of any borrow of its list, so that a member may add to or remove from the
group while it is disposed. Above a thousand disposables, removals find a disposable through an
index, as upstream switches to a dictionary; the members keep the order they were added in.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Reactive/disposables/composite_disposable.rs#L112)

## Members

- [`new`](#function-new)
- [`with_capacity`](#function-with_capacity)
- [`from_disposables`](#function-from_disposables)
- [`count`](#function-count)
- [`add`](#function-add)
- [`remove`](#function-remove)
- [`clear`](#function-clear)
- [`contains`](#function-contains)
- [`to_vec`](#function-to_vec)
- [`copy_to`](#function-copy_to)
- [`is_read_only`](#function-is_read_only)

<a id="function-new"></a>

### new

```rust
fn new() -> Rc<Self>
```

An empty group.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Reactive/disposables/composite_disposable.rs#L119)

<a id="function-with_capacity"></a>

### with_capacity

```rust
fn with_capacity(capacity: usize) -> Rc<Self>
```

An empty group with room for `capacity` disposables.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Reactive/disposables/composite_disposable.rs#L124)

<a id="function-from_disposables"></a>

### from_disposables

```rust
fn from_disposables(disposables: impl IntoIterator<Item = Rc<dyn IDisposable>>) -> Rc<Self>
```

A group of the given disposables.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Reactive/disposables/composite_disposable.rs#L132)

<a id="function-count"></a>

### count

```rust
fn count(self: &Self) -> usize
```

The number of disposables in the group.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Reactive/disposables/composite_disposable.rs#L137)

<a id="function-add"></a>

### add

```rust
fn add(self: &Self, item: Rc<dyn IDisposable>)
```

Adds a disposable; disposes it at once when the group has been disposed.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Reactive/disposables/composite_disposable.rs#L142)

<a id="function-remove"></a>

### remove

```rust
fn remove(self: &Self, item: &Rc<dyn IDisposable>) -> bool
```

Removes the disposable and disposes it; false when the group does not hold it.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Reactive/disposables/composite_disposable.rs#L151)

<a id="function-clear"></a>

### clear

```rust
fn clear(self: &Self)
```

Disposes the disposables and removes them, without disposing the group (`Clear`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Reactive/disposables/composite_disposable.rs#L166)

<a id="function-contains"></a>

### contains

```rust
fn contains(self: &Self, item: &Rc<dyn IDisposable>) -> bool
```

Whether the group holds the disposable.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Reactive/disposables/composite_disposable.rs#L177)

<a id="function-to_vec"></a>

### to_vec

```rust
fn to_vec(self: &Self) -> Vec<Rc<dyn IDisposable>>
```

The disposables of the group, in the order they were added (`ToArray`, the enumerator).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Reactive/disposables/composite_disposable.rs#L182)

<a id="function-copy_to"></a>

### copy_to

```rust
fn copy_to(self: &Self, array: &mut [Option<Rc<dyn IDisposable>>], index: usize)
```

Copies the disposables into `array` from `index` (`CopyTo`). Panics, where upstream throws
`ArgumentOutOfRangeException`, when `index` is not in the array or the disposables do not
fit; a disposed group copies nothing.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Reactive/disposables/composite_disposable.rs#L192)

<a id="function-is_read_only"></a>

### is_read_only

```rust
fn is_read_only(self: &Self) -> bool
```

Whether the group is read-only (`IsReadOnly`): never.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Reactive/disposables/composite_disposable.rs#L209)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- `Borrow<T>`
- `BorrowMut<T>`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- `Default`
- [`IDisposable`](/docs/0.5.0/api/ferroui-base/reactive/use-idisposable/)
- [`ICancelable`](/docs/0.5.0/api/ferroui-reactive/disposables/trait-icancelable/)

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
