#[factory]Expand description
Makes a type alias usable as a factory interface.
Panics
If the attributed item is not a type alias.
Examples
use std::collections::HashMap;
use syrette::interfaces::factory::IFactory;
use syrette::factory;
enum ConfigValue
{
String(String),
Bool(bool),
Int(i32),
None,
}
trait IConfigurator
{
fn configure(&self, key: String, value: ConfigValue);
}
struct Configurator {
config: HashMap<String, ConfigValue>,
}
impl Configurator
{
fn new(keys: Vec<String>) -> Self
{
Self {
config: HashMap::from(
keys
.iter()
.map(|key| (key.clone(), ConfigValue::None))
.collect::<HashMap<_, _>>()
)
}
}
}
impl IConfigurator for Configurator
{
fn configure(&self, key: String, value: ConfigValue)
{
// ...
}
}
#[factory]
type IConfiguratorFactory = dyn IFactory<(Vec<String>,), dyn IConfigurator>;