[−][src]Macro spirit::simple_fragment
A helper macro to implement a simple Fragment
.
The full implementation of a Fragment
requires a lot of work that is not usually needed.
In case the Fragment
should not implement the two-stage creation, this can be used to cut
down on the boilerplate a bit.
Examples
use failure::Error; use spirit::simple_fragment; use spirit::fragment::Installer; // The message as a resource struct Message(String); // An installer of a resource #[derive(Default)] struct MessageInstaller; impl<O, C> Installer<Message, O, C> for MessageInstaller { type UninstallHandle = (); fn install(&mut self, message: Message, _name: &str) { println!("{}", message.0); } } // Configuration of a message from the config file struct MessageCfg { msg: String, } simple_fragment! { impl Fragment for MessageCfg { type Resource = Message; type Installer = MessageInstaller; fn create(&self, _name: &'static str) -> Result<Message, Error> { Ok(Message(self.msg.clone())) } } }
If the Driver
is not provided (as in the above example), the trivial
driver is going to be used.