# FerroDictionary

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-base/collections/struct-ferrodictionary/

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

```rust
struct FerroDictionary<K, V>
```

A notifying dictionary.

Changes raise the collection changed event and property changed
notifications for `Count` and `Item[key]` (`Item` when the dictionary is
cleared). Keys are shown in those names through their `Display` form.

Enumeration works on a copy, so the dictionary may be modified from
within an enumeration or a change notification.

The dictionary is a reference object: the value is a shared handle,
clones refer to the same dictionary and handles compare by identity.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/collections/ferro_dictionary.rs#L74)

## Members

- [`ptr_eq`](#function-ptr_eq)
- [`new`](#function-new)
- [`with_capacity`](#function-with_capacity)
- [`from_dictionary`](#function-from_dictionary)
- [`add_collection_changed`](#function-add_collection_changed)
- [`remove_collection_changed`](#function-remove_collection_changed)
- [`has_collection_changed_subscribers`](#function-has_collection_changed_subscribers)
- [`count`](#function-count)
- [`is_empty`](#function-is_empty)
- [`is_read_only`](#function-is_read_only)
- [`keys`](#function-keys)
- [`values`](#function-values)
- [`get`](#function-get)
- [`try_get_value`](#function-try_get_value)
- [`set`](#function-set)
- [`add`](#function-add)
- [`clear`](#function-clear)
- [`contains_key`](#function-contains_key)
- [`contains`](#function-contains)
- [`to_vec`](#function-to_vec)
- [`copy_to`](#function-copy_to)
- [`for_each`](#function-for_each)
- [`remove`](#function-remove)

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

### ptr_eq

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

Whether two handles refer to the same dictionary.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/collections/ferro_dictionary.rs#L129)

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

### new

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

Creates an empty dictionary.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/collections/ferro_dictionary.rs#L148)

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

### with_capacity

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

Creates an empty dictionary with room for `capacity` entries.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/collections/ferro_dictionary.rs#L153)

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

### from_dictionary

```rust
fn from_dictionary(dictionary: impl IntoIterator<Item = (K, V)>) -> Self
```

Creates a dictionary with the entries of `dictionary`. A key that
occurs more than once keeps its last value.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/collections/ferro_dictionary.rs#L164)

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

### add_collection_changed

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

Subscribes to changes of the collection. Returns a token for
`remove_collection_changed`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/collections/ferro_dictionary.rs#L177)

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

### remove_collection_changed

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

Unsubscribes a handler.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/collections/ferro_dictionary.rs#L182)

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

### has_collection_changed_subscribers

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

Whether anything is subscribed to changes of the collection, typed or
untyped.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/collections/ferro_dictionary.rs#L188)

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

### count

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

The number of entries.

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

<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/collections/ferro_dictionary.rs#L197)

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

### is_read_only

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



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/collections/ferro_dictionary.rs#L201)

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

### keys

```rust
fn keys(self: &Self) -> Vec<K>
```

The keys, in enumeration order.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/collections/ferro_dictionary.rs#L206)

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

### values

```rust
fn values(self: &Self) -> Vec<V>
```

The values, in enumeration order.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/collections/ferro_dictionary.rs#L211)

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

### get

```rust
fn get(self: &Self, key: &K) -> V
```

The value for `key`. Panics if the key is not present.

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

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

### try_get_value

```rust
fn try_get_value(self: &Self, key: &K) -> Option<V>
```

The value for `key`, if present.

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

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

### set

```rust
fn set(self: &Self, key: K, value: V)
```

Sets the value for `key`, adding the entry if it is not present.

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

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

### add

```rust
fn add(self: &Self, key: K, value: V)
```

Adds an entry. Panics if the key is already present.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/collections/ferro_dictionary.rs#L247)

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

### clear

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

Removes all entries.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/collections/ferro_dictionary.rs#L260)

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

### contains_key

```rust
fn contains_key(self: &Self, key: &K) -> bool
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/collections/ferro_dictionary.rs#L271)

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

### contains

```rust
fn contains(self: &Self, key: &K, value: &V) -> bool
where V: PartialEq
```

Whether the dictionary has the entry `key` with a value equal to
`value`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/collections/ferro_dictionary.rs#L277)

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

### to_vec

```rust
fn to_vec(self: &Self) -> Vec<(K, V)>
```

The entries, in enumeration order.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/collections/ferro_dictionary.rs#L285)

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

### copy_to

```rust
fn copy_to(self: &Self, array: &mut [(K, V)], array_index: usize)
```

Copies the entries, in enumeration order, to `array`, starting at
`array_index` (`CopyTo`).
## Panics
Panics if `array` is too small, as the managed original throws.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/collections/ferro_dictionary.rs#L294)

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

### for_each

```rust
fn for_each(self: &Self, f: impl FnMut(&K, &V) -> ())
```

Calls `f` for each entry of a copy of the dictionary.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/collections/ferro_dictionary.rs#L304)

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

### remove

```rust
fn remove(self: &Self, key: &K) -> bool
```

Removes the entry for `key`. Returns false if it is not present.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/collections/ferro_dictionary.rs#L311)

## 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`
- [`WeakEventSender`](/docs/0.5.0/api/ferroui-base/utilities/trait-weakeventsender/)
- `Clone`
- `PartialEq`
- `Debug`
- `Default`
- [`INotifyCollectionChanged`](/docs/0.5.0/api/ferroui-base/data/model/use-inotifycollectionchanged/)
- [`INotifyPropertyChanged`](/docs/0.5.0/api/ferroui-base/data/model/use-inotifypropertychanged/)
- [`IFerroDictionary<K, V>`](/docs/0.5.0/api/ferroui-base/collections/trait-iferrodictionary/)
- [`IFerroReadOnlyDictionary<K, V>`](/docs/0.5.0/api/ferroui-base/collections/trait-iferroreadonlydictionary/)
- [`MarkupTyped`](/docs/0.5.0/api/ferroui-base/metadata/trait-markuptyped/)
- [`ValueTypeRegistration`](/docs/0.5.0/api/ferroui-base/data/core/trait-valuetyperegistration/)

## Availability

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