AnyView

Type Alias AnyView 

Source
pub type AnyView = Box<dyn View>;
Expand description

type erased View

Views in Floem are strongly typed. AnyView allows you to escape the strong typing by converting any type implementing View into the AnyView type.

§Bad Example

 use floem::views::*;
 use floem::widgets::*;
 use floem::reactive::{RwSignal, SignalGet};

 let check = true;

 container(if check == true {
     checkbox(|| true)
 } else {
     label(|| "no check".to_string())
 });

The above example will fail to compile because container is expecting a single type implementing View so the if and the else must return the same type. However the branches return different types. The solution to this is to use the IntoView::into_any method to escape the strongly typed requirement.

use floem::reactive::{RwSignal, SignalGet};
use floem::views::*;
use floem::{IntoView, View};

let check = true;

container(if check == true {
    checkbox(|| true).into_any()
} else {
    label(|| "no check".to_string()).into_any()
});

Aliased Type§

pub struct AnyView(/* private fields */);