use super::Shape;
pub trait ProvidesShape {
fn provide_shape(&self) -> &dyn Shape;
}
impl<TProvidesShape> ProvidesShape for Box<TProvidesShape>
where
TProvidesShape: ProvidesShape,
{
fn provide_shape(&self) -> &dyn Shape {
(**self).provide_shape()
}
}
struct ShapeProvider<TFunc>
where
TFunc: Fn() -> &'static dyn Shape,
{
func: TFunc,
}
impl<TFunc> ProvidesShape for ShapeProvider<TFunc>
where
TFunc: Fn() -> &'static dyn Shape,
{
fn provide_shape(&self) -> &dyn Shape {
(self.func)()
}
}
#[allow(dead_code)]
fn shape_provider<TFunc: Fn() -> &'static dyn Shape>(t_func: TFunc) -> ShapeProvider<TFunc> {
ShapeProvider { func: t_func }
}