# ObservableCollection

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-system/collections/object_model/struct-observablecollection/

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

```rust
struct ObservableCollection<T>
```

A list that notifies its changes (`ObservableCollection<T>`): a shared handle, as the object
of .NET is a reference. Each change raises `PropertyChanged` for `Count` and `Item[]` as it
applies, then `CollectionChanged`, in .NET's order.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/collections/object_model/observable_collection.rs#L30)

## Members

- [`new`](#function-new)
- [`from_items`](#function-from_items)
- [`ptr_eq`](#function-ptr_eq)
- [`add_collection_changed`](#function-add_collection_changed)
- [`remove_collection_changed`](#function-remove_collection_changed)
- [`count`](#function-count)
- [`is_empty`](#function-is_empty)
- [`get`](#function-get)
- [`items`](#function-items)
- [`to_vec`](#function-to_vec)
- [`contains`](#function-contains)
- [`index_of`](#function-index_of)
- [`add`](#function-add)
- [`insert`](#function-insert)
- [`set`](#function-set)
- [`remove_at`](#function-remove_at)
- [`remove`](#function-remove)
- [`move_item`](#function-move_item)
- [`clear`](#function-clear)
- [`items_mut_silent`](#function-items_mut_silent)
- [`set_notifications_suspended`](#function-set_notifications_suspended)
- [`notifications_suspended`](#function-notifications_suspended)
- [`check_reentrancy`](#function-check_reentrancy)
- [`on_property_changed`](#function-on_property_changed)
- [`on_count_property_changed`](#function-on_count_property_changed)
- [`on_indexer_property_changed`](#function-on_indexer_property_changed)
- [`on_collection_reset`](#function-on_collection_reset)
- [`on_collection_changed`](#function-on_collection_changed)

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

### new

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

An empty collection.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/collections/object_model/observable_collection.rs#L55)

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

### from_items

```rust
fn from_items(items: Vec<T>) -> Self
```

A collection of the items (`ObservableCollection(IEnumerable<T>)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/collections/object_model/observable_collection.rs#L60)

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

### ptr_eq

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

Whether `self` and `other` are the same collection.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/collections/object_model/observable_collection.rs#L74)

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

### add_collection_changed

```rust
fn add_collection_changed(self: &Self, handler: Rc<CollectionChangedHandler<T>>) -> u64
```

Adds a handler of the typed change notifications; returns the token that removes it
(`CollectionChanged +=`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/collections/object_model/observable_collection.rs#L80)

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

### remove_collection_changed

```rust
fn remove_collection_changed(self: &Self, token: u64) -> bool
```

Removes a handler (`CollectionChanged -=`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/collections/object_model/observable_collection.rs#L85)

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

### count

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

The number of items (`Count`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/collections/object_model/observable_collection.rs#L90)

<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.System/collections/object_model/observable_collection.rs#L94)

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

### get

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

The item at `index` (the indexer's getter).
## Panics
When `index` is out of range (`ArgumentOutOfRangeException`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/collections/object_model/observable_collection.rs#L102)

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

### items

```rust
fn items(self: &Self) -> Ref<'_, Vec<T>>
```

The items, borrowed.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/collections/object_model/observable_collection.rs#L107)

<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.System/collections/object_model/observable_collection.rs#L112)

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

### contains

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

Whether the collection has `item` (`Contains`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/collections/object_model/observable_collection.rs#L117)

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

### index_of

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

The index of `item` (`IndexOf`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/collections/object_model/observable_collection.rs#L122)

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

### add

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

Adds an item at the end (`Add`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/collections/object_model/observable_collection.rs#L127)

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

### insert

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

Inserts an item (`InsertItem`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/collections/object_model/observable_collection.rs#L133)

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

### set

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

Replaces the item at `index` (the indexer's setter, `SetItem`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/collections/object_model/observable_collection.rs#L142)

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

### remove_at

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

Removes the item at `index` (`RemoveItem`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/collections/object_model/observable_collection.rs#L150)

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

### remove

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

Removes `item`; false when it is not there (`Remove`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/collections/object_model/observable_collection.rs#L159)

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

### move_item

```rust
fn move_item(self: &Self, old_index: usize, new_index: usize)
```

Moves the item at `old_index` to `new_index` (`Move`, `MoveItem`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/collections/object_model/observable_collection.rs#L170)

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

### clear

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

Removes every item (`ClearItems`): a reset.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/collections/object_model/observable_collection.rs#L183)

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

### items_mut_silent

```rust
fn items_mut_silent(self: &Self) -> RefMut<'_, Vec<T>>
```

The items to change without notifications (the protected `Items` of `Collection<T>`), for
a collection that raises its own notifications afterwards.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/collections/object_model/observable_collection.rs#L193)

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

### set_notifications_suspended

```rust
fn set_notifications_suspended(self: &Self, suspended: bool)
```

Holds back the notifications until `false` (the overrides of `OnCollectionChanged` and
`OnPropertyChanged` of a collection that suspends them).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/collections/object_model/observable_collection.rs#L199)

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

### notifications_suspended

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



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/collections/object_model/observable_collection.rs#L203)

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

### check_reentrancy

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

Panics on a change made by a handler of a notification while more than one handler listens
(`CheckReentrancy`, `InvalidOperationException`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/collections/object_model/observable_collection.rs#L209)

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

### on_property_changed

```rust
fn on_property_changed(self: &Self, name: &str)
```

Raises `PropertyChanged` for `name` (`OnPropertyChanged`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/collections/object_model/observable_collection.rs#L216)

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

### on_count_property_changed

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

`OnCountPropertyChanged`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/collections/object_model/observable_collection.rs#L224)

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

### on_indexer_property_changed

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

`OnIndexerPropertyChanged`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/collections/object_model/observable_collection.rs#L229)

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

### on_collection_reset

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

A reset (`OnCollectionReset`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/collections/object_model/observable_collection.rs#L234)

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

### on_collection_changed

```rust
fn on_collection_changed(self: &Self, action: NotifyCollectionChangedAction, new_items: &[T], old_items: &[T], new_starting_index: i32, old_starting_index: i32)
```

Raises `CollectionChanged` (`OnCollectionChanged`), with the typed and the untyped
handlers, blocking re-entrant changes meanwhile (`BlockReentrancy`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.System/collections/object_model/observable_collection.rs#L240)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- `Borrow<T>`
- `BorrowMut<T>`
- `CloneToUninit`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- `ToOwned`
- `Clone`
- `Default`
- `PartialEq`
- [`INotifyCollectionChanged`](/docs/0.5.0/api/ferroui-base/data/model/use-inotifycollectionchanged/)
- [`INotifyPropertyChanged`](/docs/0.5.0/api/ferroui-base/data/model/use-inotifypropertychanged/)

## Availability

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