use crate::runtime::Task; use std::borrow::Cow; use std::fmt; /// A specific boot strategy for a [`Program`](crate::Program). pub struct Preset { name: Cow<'static, str>, boot: Box (State, Task)>, } impl Preset { /// Creates a new [`Preset`] with the given name and boot strategy. pub fn new( name: impl Into>, boot: impl Fn() -> (State, Task) + 'static, ) -> Self { Self { name: name.into(), boot: Box::new(boot), } } /// Returns the name of the [`Preset`]. pub fn name(&self) -> &str { &self.name } /// Boots the [`Preset`], returning the initial [`Program`](crate::Program) state and /// a [`Task`] for concurrent booting. pub fn boot(&self) -> (State, Task) { (self.boot)() } } impl fmt::Debug for Preset { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Preset") .field("name", &self.name) .finish_non_exhaustive() } }