diff options
author | 2019-11-21 18:00:27 +0100 | |
---|---|---|
committer | 2019-11-21 18:00:27 +0100 | |
commit | ba56a561b254c9a5f3d23cb54d23dc311759ab4c (patch) | |
tree | 3d262b1e892d83f7493a99737a267204a191e317 /src/sandbox.rs | |
parent | 428509c84a142a653be3ec4bbff0c23c466c44fa (diff) | |
download | iced-ba56a561b254c9a5f3d23cb54d23dc311759ab4c.tar.gz iced-ba56a561b254c9a5f3d23cb54d23dc311759ab4c.tar.bz2 iced-ba56a561b254c9a5f3d23cb54d23dc311759ab4c.zip |
Implement `iced::Sandbox` trait for simple apps
Diffstat (limited to 'src/sandbox.rs')
-rw-r--r-- | src/sandbox.rs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/sandbox.rs b/src/sandbox.rs new file mode 100644 index 00000000..8ff374f7 --- /dev/null +++ b/src/sandbox.rs @@ -0,0 +1,45 @@ +use crate::{Application, Command, Element}; + +pub trait Sandbox { + type Message: std::fmt::Debug + Send; + + fn new() -> Self; + + fn title(&self) -> String; + + fn update(&mut self, message: Self::Message); + + fn view(&mut self) -> Element<Self::Message>; + + fn run() + where + Self: 'static + Sized, + { + <Self as Application>::run() + } +} + +impl<T> Application for T +where + T: Sandbox, +{ + type Message = T::Message; + + fn new() -> (Self, Command<T::Message>) { + (T::new(), Command::none()) + } + + fn title(&self) -> String { + T::title(self) + } + + fn update(&mut self, message: T::Message) -> Command<T::Message> { + T::update(self, message); + + Command::none() + } + + fn view(&mut self) -> Element<T::Message> { + T::view(self) + } +} |