# Interaction

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

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

```rust
struct Interaction<I, O>
```

An interaction between collaborating parts of an application (`Interaction<TInput, TOutput>`).
It is a shared handle: clones are the same interaction.

The handlers run in the reverse order of their registration: the handler registered last has
the first chance to handle a question. A handler need not handle it, and leaves it to the next
one; `handle` fails with an [`UnhandledInteractionError`](/docs/0.5.0/api/ferroui-reactiveui/binding/interactions/struct-unhandledinteractionerror/) when no handler
set an output.

Deviation (DEVIATIONS.md, ReactiveUI): upstream's virtual members (`Handle`, `GenerateContext`)
and protected `GetHandlers` serve subclasses; Rust has none, so `handle` and
`get_handlers` are public and the context is always an
[`InteractionContext`](/docs/0.5.0/api/ferroui-reactiveui/binding/interactions/struct-interactioncontext/). A handler that throws upstream faults the question; here a handler that
panics does, its panic caught as a [`PanicError`](/docs/0.5.0/api/ferroui-reactiveui/struct-panicerror/).

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

## Members

- [`new`](#function-new)
- [`with_scheduler`](#function-with_scheduler)
- [`register_handler`](#function-register_handler)
- [`register_handler_task`](#function-register_handler_task)
- [`register_handler_observable`](#function-register_handler_observable)
- [`handle`](#function-handle)
- [`when_handled`](#function-when_handled)
- [`get_handlers`](#function-get_handlers)

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

### new

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

An interaction that invokes its handlers on the thread that asks (`Interaction()`).

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

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

### with_scheduler

```rust
fn with_scheduler(handler_scheduler: Option<Rc<dyn IScheduler>>) -> Self
```

An interaction that invokes each handler on `handler_scheduler`, such as the main thread's;
`None` invokes them on the thread that asks (`Interaction(IScheduler?)`).

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

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

### register_handler

```rust
fn register_handler(self: &Self, handler: impl Fn(Rc<dyn IInteractionContext<I, O>>) -> () + 'static) -> 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/interaction.rs#L84)

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

### register_handler_task

```rust
fn register_handler_task<Fut: Future<Output = Result<(), ObservableError>> + 'static>(self: &Self, handler: impl Fn(Rc<dyn IInteractionContext<I, O>>) -> Fut + 'static) -> Rc<dyn IDisposable>
```

Registers an asynchronous handler: the future it gives runs as a task of the thread, and
the next handler runs when it has ended (`RegisterHandler(Func<IInteractionContext<TInput,
TOutput>, Task>)`). The `flatten()` of a `Shared` or of a `oneshot` receiver is such a
future.

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

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

### register_handler_observable

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

Registers a handler that finishes when the observable it gives ends; its values are ignored,
and its error faults the question (`RegisterHandler<TDontCare>(Func<IInteractionContext<TInput,
TOutput>, IObservable<TDontCare>>)`).

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

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

### handle

```rust
fn handle(self: &Self, input: I) -> Shared<Result<O, ObservableError>>
```

Runs the handlers, latest registered first, until one sets an output, and gives a task of
that output, the `Shared` of its result (`flatten()` is a future of it); the task fails
with an `UnhandledInteractionError` when no handler set one (`Handle(TInput)`).

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

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

### when_handled

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

Asks the question as an observable: each subscription runs `handle` once,
then notifies the output and ends, or fails with an `UnhandledInteractionError`
(`WhenHandled(TInput)`). Disposing the subscription drops the output; a handler that is
running still finishes.

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

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

### get_handlers

```rust
fn get_handlers(self: &Self) -> Vec<InteractionHandler<I, O>>
```

A copy of the registered handlers, earliest first (`GetHandlers()`).

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

## 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`
- `PartialEq`
- `Debug`
- `Default`
- [`IInteraction<I, O>`](/docs/0.5.0/api/ferroui-reactiveui/binding/interactions/trait-iinteraction/)
- [`InteractionValue`](/docs/0.5.0/api/ferroui-reactiveui/binding/mixins/trait-interactionvalue/)

## Availability

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