parent
28564b11bd
commit
1a52695945
@ -0,0 +1,24 @@ |
||||
use super::component::Component; |
||||
use super::model_i::{Context, FromContext}; |
||||
|
||||
use std::any::{Any, type_name}; |
||||
|
||||
trait ComponentFactory { |
||||
type Input; |
||||
type Output; |
||||
|
||||
fn build(&self, input: Self::Input) -> Result<Self::Output, String>; |
||||
} |
||||
|
||||
trait ContextComponentFactory: ComponentFactory { |
||||
fn build_from_context(&self, context: &Context) -> Result<Self::Output, String>; |
||||
} |
||||
|
||||
impl <T:Any + Sized + 'static, O, CF: ComponentFactory<Input=Component<T>, Output=O>> ContextComponentFactory for CF { |
||||
fn build_from_context(&self, context: &Context) -> Result<Self::Output, String> { |
||||
let input = FromContext::from(context).ok_or_else(|| format!("Could not find retrieve component of type {} from context", type_name::<T>()))?; |
||||
self.build(input) |
||||
} |
||||
} |
||||
|
||||
|
@ -1,3 +1,4 @@ |
||||
mod model_i; |
||||
mod component; |
||||
mod component_map; |
||||
mod component_factory; |
||||
|
Loading…
Reference in new issue