# IInteraction

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-reactiveui/binding/interactions/trait-iinteraction/

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

```rust
trait IInteraction<I, O>
```

An interaction between collaborating parts of an application (`IInteraction<TInput, TOutput>`):
one part asks a question (the input), and a handler that another part registered answers it
(the output). Typically a view model asks its view for a confirmation.

Deviation (DEVIATIONS.md, ReactiveUI): the handlers are shared closures, so that the trait can
be a trait object; the asynchronous handler gives a task, the `Shared` of a
`Result<(), ObservableError>`, and the observable-based one an
observable of `()` (upstream's `TDontCare`: its values are ignored). `Interaction`
itself has generic forms that take any closure.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/binding/interactions/i_interaction.rs#L17)

## Members

- [`register_handler`](#function-register_handler)
- [`register_handler_task`](#function-register_handler_task)
- [`register_handler_observable`](#function-register_handler_observable)
- [`handle`](#function-handle)

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

### register_handler

```rust
fn register_handler(self: &Self, handler: Rc<dyn Fn(Rc<dyn IInteractionContext<I, O>>) -> ()>) -> Rc<dyn IDisposable>
```

Registers a synchronous handler; disposing the result unregisters it
(`RegisterHandler(Action<IInteractionContext<TInput, TOutput>>)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/binding/interactions/i_interaction.rs#L20)

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

### register_handler_task

```rust
fn register_handler_task(self: &Self, handler: Rc<dyn Fn(Rc<dyn IInteractionContext<I, O>>) -> Shared<Result<(), ObservableError>>>) -> Rc<dyn IDisposable>
```

Registers a task-based asynchronous handler; disposing the result unregisters it
(`RegisterHandler(Func<IInteractionContext<TInput, TOutput>, Task>)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/binding/interactions/i_interaction.rs#L24)

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

### register_handler_observable

```rust
fn register_handler_observable(self: &Self, handler: Rc<dyn Fn(Rc<dyn IInteractionContext<I, O>>) -> Rc<dyn IObservable<()>>>) -> Rc<dyn IDisposable>
```

Registers an observable-based asynchronous handler, which finishes when its observable ends
(`RegisterHandler<TDontCare>(Func<IInteractionContext<TInput, TOutput>, IObservable<TDontCare>>)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/binding/interactions/i_interaction.rs#L31)

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

### handle

```rust
fn handle(self: &Self, input: I) -> Rc<dyn IObservable<O>>
```

Asks the question: a cold observable that runs the handlers, latest registered first, until
one sets an output, each time it is subscribed, then notifies the output and ends. It fails
with `UnhandledInteractionError` when no handler
sets one (`Handle(TInput)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/binding/interactions/i_interaction.rs#L40)

## Trait implementations

- [`IInteraction<I, O>`](/docs/0.5.0/api/ferroui-reactiveui/binding/interactions/trait-iinteraction/)

## Availability

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