# MediaCollection

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-base/media/struct-mediacollection/

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

```rust
struct MediaCollection<T: Clone + 'static>
```

A shared, observable list. Cloning the handle shares the list; equality is
by identity.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/media_collection.rs#L21)

## Members

- [`new`](#function-new)
- [`from_items`](#function-from_items)
- [`from_list`](#function-from_list)
- [`list`](#function-list)
- [`ptr_eq`](#function-ptr_eq)
- [`reset_behavior`](#function-reset_behavior)
- [`set_reset_behavior`](#function-set_reset_behavior)
- [`len`](#function-len)
- [`is_empty`](#function-is_empty)
- [`get`](#function-get)
- [`to_vec`](#function-to_vec)
- [`iter`](#function-iter)
- [`add`](#function-add)
- [`add_range`](#function-add_range)
- [`insert`](#function-insert)
- [`remove_at`](#function-remove_at)
- [`clear`](#function-clear)
- [`collection_changed`](#function-collection_changed)
- [`for_each_item`](#function-for_each_item)
- [`set`](#function-set)
- [`contains`](#function-contains)
- [`index_of`](#function-index_of)
- [`remove`](#function-remove)

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

### new

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

Creates an empty list.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/media_collection.rs#L59)

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

### from_items

```rust
fn from_items(items: impl IntoIterator<Item = T>) -> Self
```

Creates a list holding `items`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/media_collection.rs#L64)

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

### from_list

```rust
fn from_list(list: Rc<FerroList<T>>) -> Self
```

Wraps an existing list.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/media_collection.rs#L69)

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

### list

```rust
fn list(self: &Self) -> &Rc<FerroList<T>>
```

The underlying list.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/media_collection.rs#L75)

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

### ptr_eq

```rust
fn ptr_eq(self: &Self, other: &Self) -> bool
```

Whether both handles refer to the same list.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/media_collection.rs#L81)

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

### reset_behavior

```rust
fn reset_behavior(self: &Self) -> ResetBehavior
```

The action notified when the list is cleared.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/media_collection.rs#L87)

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

### set_reset_behavior

```rust
fn set_reset_behavior(self: &Self, value: ResetBehavior)
```

Sets the action notified when the list is cleared.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/media_collection.rs#L93)

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

### len

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

The number of items.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/media_collection.rs#L99)

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

### is_empty

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



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/media_collection.rs#L104)

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

### get

```rust
fn get(self: &Self, index: usize) -> T
```

The item at `index`. Panics if the index is out of range.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/media_collection.rs#L110)

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

### to_vec

```rust
fn to_vec(self: &Self) -> Vec<T>
```

A copy of the items.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/media_collection.rs#L116)

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

### iter

```rust
fn iter(self: &Self) -> std::vec::IntoIter<T>
```

Iterates over a snapshot of the items.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/media_collection.rs#L122)

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

### add

```rust
fn add(self: &Self, item: T)
```

Appends an item.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/media_collection.rs#L128)

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

### add_range

```rust
fn add_range(self: &Self, items: impl IntoIterator<Item = T>)
```

Appends several items with a single notification.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/media_collection.rs#L134)

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

### insert

```rust
fn insert(self: &Self, index: usize, item: T)
```

Inserts an item at `index`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/media_collection.rs#L140)

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

### remove_at

```rust
fn remove_at(self: &Self, index: usize)
```

Removes the item at `index`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/media_collection.rs#L146)

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

### clear

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

Removes all items.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/media_collection.rs#L152)

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

### collection_changed

```rust
fn collection_changed(self: &Self, handler: impl Fn(&'a NotifyCollectionChangedEventArgs<'b, T>) -> () + 'static) -> Subscription
```

Subscribes to changes of the list. Dropping the returned guard removes
the handler; `Subscription::detach` keeps it for the life of the
list.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/media_collection.rs#L159)

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

### for_each_item

```rust
fn for_each_item(self: &Self, added: impl Fn(usize, &T) -> () + 'static, removed: impl Fn(usize, &T) -> () + 'static, reset: impl Fn() -> () + 'static) -> Subscription
```

Invokes `added` for every item currently in the list and for every item
added later, `removed` for every item removed and `reset` when the list
is reset. Dropping the returned guard stops the calls for later
changes; `Subscription::detach` keeps them for the life of the list.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/media_collection.rs#L176)

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

### set

```rust
fn set(self: &Self, index: usize, value: T)
```

Replaces the item at `index`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/media_collection.rs#L228)

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

### contains

```rust
fn contains(self: &Self, item: &T) -> bool
```

Whether the list contains `item`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/media_collection.rs#L234)

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

### index_of

```rust
fn index_of(self: &Self, item: &T) -> Option<usize>
```

The index of the first occurrence of `item`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/media_collection.rs#L240)

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

### remove

```rust
fn remove(self: &Self, item: &T) -> bool
```

Removes the first occurrence of `item`; returns whether it was found.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/media_collection.rs#L246)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- [`PropertyValue`](/docs/0.5.0/api/ferroui-base/trait-propertyvalue/)
- [`AnyValue`](/docs/0.5.0/api/ferroui-base/trait-anyvalue/)
- [`ClassDefaults`](/docs/0.5.0/api/ferroui-base/trait-classdefaults/)
- `Borrow<T>`
- `BorrowMut<T>`
- `CloneToUninit`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- `ToOwned`
- `ErasedDestructor`
- `IntoEither`
- `Clone`
- `PartialEq`
- `Default`
- `Debug`
- `FromIterator<T>`
- [`MarkupTyped`](/docs/0.5.0/api/ferroui-base/metadata/trait-markuptyped/)

## Availability

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