# MessageBusExtensions

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-reactiveui-testing/trait-messagebusextensions/

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

```rust
trait MessageBusExtensions
```

Runs code with a message bus as `MessageBus::current` (`MessageBusExtensions`).

Deviation (DEVIATIONS.md, ReactiveUI): the current message bus is per thread, so upstream's
lock (`Monitor.Enter(messageBusGate)`), which keeps the tests of other threads from replacing
it in between, is not needed and not ported.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI.Testing/message_bus_extensions.rs#L23)

## Members

- [`as_message_bus`](#function-as_message_bus)
- [`with_message_bus`](#function-with_message_bus)
- [`with`](#function-with)

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

### as_message_bus

```rust
fn as_message_bus(self: &Self) -> Rc<dyn IMessageBus>
```

The message bus as the handle that `MessageBus::current` holds.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI.Testing/message_bus_extensions.rs#L25)

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

### with_message_bus

```rust
fn with_message_bus(self: &Self) -> Rc<dyn IDisposable>
```

Makes the message bus `MessageBus::current` until the returned disposable is disposed,
which restores the message bus that was current before (`WithMessageBus`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI.Testing/message_bus_extensions.rs#L29)

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

### with

```rust
fn with<R>(self: &Self, block: impl FnOnce() -> R) -> R
```

Runs `block` with the message bus as `MessageBus::current` and returns its result; the
message bus current before is restored afterwards, also when `block` panics
(`With<TRet>(Func<TRet>)`, and `With(Action)` with a block that returns `()`).

Not ported: the `ArgumentException` of a null block - argument validation.

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

## Trait implementations

- [`MessageBusExtensions`](/docs/0.5.0/api/ferroui-reactiveui-testing/trait-messagebusextensions/)

## Availability

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