# IKeyIndexMapping

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-controls/trait-ikeyindexmapping/

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

```rust
trait IKeyIndexMapping
```

Provides methods that let an items source give each item a unique key, which stays the
same while the item is in the source, whatever its index (WinUI `IKeyIndexMapping`).

An `IItemsList` states that it implements the contract through
`key_index_mapping`;
`ItemsSourceView::has_key_index_mapping`
reports it, and a control that realizes items can keep the element of an item across a
reset of the source by its key.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/i_key_index_mapping.rs#L14)

## Members

- [`key_from_index`](#function-key_from_index)
- [`index_from_key`](#function-index_from_key)

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

### key_from_index

```rust
fn key_from_index(self: &Self, index: i32) -> String
```

Retrieves the unique key of the item at the specified index.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/i_key_index_mapping.rs#L16)

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

### index_from_key

```rust
fn index_from_key(self: &Self, key: &str) -> i32
```

Retrieves the index of the item that has the specified unique key, or `-1` when no item
has it.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/i_key_index_mapping.rs#L20)

## Trait implementations

- [`IKeyIndexMapping`](/docs/0.5.0/api/ferroui-controls/trait-ikeyindexmapping/)

## Availability

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