# IViewFor

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

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

```rust
trait IViewFor: IActivatableView
```

A view that displays a view model (`IViewFor`). A view is shared as an `Rc`.

This is the form of a view that does not name the type of its view model: the view model is an
`Rc<dyn Any>`. A view of a known view model also implements [`IViewForOf<VM>`](/docs/0.5.0/api/ferroui-reactiveui/binding/interfaces/trait-iviewforof/), and the macro
`view_for!` writes both traits (with [`IActivatableView`](/docs/0.5.0/api/ferroui-reactiveui/binding/interfaces/trait-iactivatableview/)) from the typed
accessors.

The trait is object safe, so that a view is held as `Rc<dyn IViewFor>`; it is `Any` (through
[`IActivatableView`](/docs/0.5.0/api/ferroui-reactiveui/binding/interfaces/trait-iactivatableview/)), so that `Rc<dyn IViewFor>` upcasts to `Rc<dyn Any>` and downcasts to the
type of the view.

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

## Members

- [`view_model`](#function-view_model)
- [`set_view_model`](#function-set_view_model)
- [`as_view_for_of`](#function-as_view_for_of)

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

### view_model

```rust
fn view_model(self: &Self) -> Option<Rc<dyn Any>>
```

The view model displayed by the view (the getter of `ViewModel`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/binding/interfaces/i_view_for.rs#L19)

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

### set_view_model

```rust
fn set_view_model(self: &Self, view_model: Option<Rc<dyn Any>>)
```

Sets the view model displayed by the view (the setter of `ViewModel`). A typed view panics
when `view_model` is of another type than its own, as the cast of upstream's views throws.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/binding/interfaces/i_view_for.rs#L23)

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

### as_view_for_of

```rust
fn as_view_for_of(self: Rc<Self>) -> Option<Box<dyn Any>>
```

The view as an `Rc<dyn IViewForOf<VM>>` in a `Box<dyn Any>`, for the type `VM` of view
model it is typed for, or `None` for a view that names no type.

Not an upstream member: upstream asks `view is IViewFor<TViewModel>` at run time, which
Rust cannot ask of a trait object. `view_for_of` reads it; `view_for!`
writes it, and a view implementing the traits by hand returns
`typed_view_for``::<VM, Self>(self)`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/binding/interfaces/i_view_for.rs#L34)

## Availability

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