# UndoRedoHelper

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-controls/utils/struct-undoredohelper/

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

```rust
struct UndoRedoHelper<TState>
```

Records snapshots of the state of a host and moves between them.

The host owns its helper, so the helper only holds a weak handle to the
host. No borrow of the helper is held while the host is called: the host
may call back into the helper from every member of [`IUndoRedoHost`](/docs/0.5.0/api/ferroui-controls/utils/trait-iundoredohost/).

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

## Members

- [`DEFAULT_UNDO_LIMIT`](#assoc_const-default_undo_limit)
- [`new`](#function-new)
- [`unattached`](#function-unattached)
- [`set_host`](#function-set_host)
- [`limit`](#function-limit)
- [`set_limit`](#function-set_limit)
- [`can_undo`](#function-can_undo)
- [`can_redo`](#function-can_redo)
- [`undo`](#function-undo)
- [`is_last_state`](#function-is_last_state)
- [`try_get_last_state`](#function-try_get_last_state)
- [`has_state`](#function-has_state)
- [`update_last_state_with`](#function-update_last_state_with)
- [`update_last_state`](#function-update_last_state)
- [`discard_redo`](#function-discard_redo)
- [`redo`](#function-redo)
- [`snapshot`](#function-snapshot)
- [`clear`](#function-clear)

<a id="assoc_const-default_undo_limit"></a>

### DEFAULT_UNDO_LIMIT

```rust
const DEFAULT_UNDO_LIMIT: i32
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/utils/undo_redo_helper.rs#L41)

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

### new

```rust
fn new(host: Weak<dyn IUndoRedoHost<TState>>) -> Self
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/utils/undo_redo_helper.rs#L43)

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

### unattached

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

Creates a helper whose host is set later with `set_host`
(Self::set_host): the field initialisers of a class run before its
handle exists.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/utils/undo_redo_helper.rs#L52)

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

### set_host

```rust
fn set_host(self: &Self, host: Weak<dyn IUndoRedoHost<TState>>)
```

Sets the host of a helper created with `unattached`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/utils/undo_redo_helper.rs#L62)

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

### limit

```rust
fn limit(self: &Self) -> i32
```

Maximum number of states this helper can store for undo/redo.
If -1, no limit is imposed.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/utils/undo_redo_helper.rs#L72)

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

### set_limit

```rust
fn set_limit(self: &Self, value: i32)
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/utils/undo_redo_helper.rs#L76)

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

### can_undo

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



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/utils/undo_redo_helper.rs#L80)

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

### can_redo

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



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/utils/undo_redo_helper.rs#L84)

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

### undo

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



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/utils/undo_redo_helper.rs#L88)

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

### is_last_state

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



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/utils/undo_redo_helper.rs#L104)

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

### try_get_last_state

```rust
fn try_get_last_state(self: &Self) -> Option<TState>
```

The current state when it is the last one (C# `TryGetLastState(out state)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/utils/undo_redo_helper.rs#L113)

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

### has_state

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



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/utils/undo_redo_helper.rs#L125)

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

### update_last_state_with

```rust
fn update_last_state_with(self: &Self, state: TState)
```

Replaces the last recorded state (C# `UpdateLastState(TState)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/utils/undo_redo_helper.rs#L130)

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

### update_last_state

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

Replaces the last recorded state with the state of the host
(C# `UpdateLastState()`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/utils/undo_redo_helper.rs#L138)

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

### discard_redo

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



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/utils/undo_redo_helper.rs#L145)

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

### redo

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



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/utils/undo_redo_helper.rs#L155)

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

### snapshot

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



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/utils/undo_redo_helper.rs#L171)

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

### clear

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



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/utils/undo_redo_helper.rs#L212)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- `Borrow<T>`
- `BorrowMut<T>`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- [`ClassDefaults`](/docs/0.5.0/api/ferroui-base/trait-classdefaults/)
- `ErasedDestructor`
- `IntoEither`

## Availability

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