#[cfg_attr(target_arch = "wasm32", path = "web.rs")] #[cfg_attr(not(target_arch = "wasm32"), path = "winit.rs")] mod platform; pub use platform::*; pub trait Application { type Message: std::fmt::Debug; fn title(&self) -> String; fn update(&mut self, message: Self::Message); fn view(&mut self) -> Element; fn run(self) where Self: 'static + Sized, { #[cfg(not(target_arch = "wasm32"))] iced_winit::Application::run(Instance(self)); #[cfg(target_arch = "wasm32")] iced_web::Application::run(Instance(self)); } } struct Instance(A); #[cfg(not(target_arch = "wasm32"))] impl iced_winit::Application for Instance where A: Application, { type Renderer = Renderer; type Message = A::Message; fn title(&self) -> String { self.0.title() } fn update(&mut self, message: Self::Message) { self.0.update(message); } fn view(&mut self) -> Element { self.0.view() } } #[cfg(target_arch = "wasm32")] impl iced_web::Application for Instance where A: Application, { type Message = A::Message; fn update(&mut self, message: Self::Message) { self.0.update(message); } fn view(&mut self) -> Element { self.0.view() } }