From 2d1a6b2d432408d74eb57e0bda3f7434617e1070 Mon Sep 17 00:00:00 2001 From: HampusM Date: Wed, 20 Jul 2022 14:29:45 +0200 Subject: refactor: reorganize folder hierarchy --- src/castable_factory.rs | 76 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 src/castable_factory.rs (limited to 'src/castable_factory.rs') diff --git a/src/castable_factory.rs b/src/castable_factory.rs new file mode 100644 index 0000000..5d582bb --- /dev/null +++ b/src/castable_factory.rs @@ -0,0 +1,76 @@ +use crate::interfaces::factory::IFactory; +use crate::libs::intertrait::CastFrom; +use crate::ptr::InterfacePtr; + +pub trait AnyFactory: CastFrom {} + +pub struct CastableFactory +where + Args: 'static, + ReturnInterface: 'static + ?Sized, +{ + func: &'static dyn Fn>, +} + +impl CastableFactory +where + Args: 'static, + ReturnInterface: 'static + ?Sized, +{ + pub fn new( + func: &'static dyn Fn>, + ) -> Self + { + Self { func } + } +} + +impl IFactory + for CastableFactory +where + Args: 'static, + ReturnInterface: 'static + ?Sized, +{ +} + +impl Fn for CastableFactory +where + Args: 'static, + ReturnInterface: 'static + ?Sized, +{ + extern "rust-call" fn call(&self, args: Args) -> Self::Output + { + self.func.call(args) + } +} + +impl FnMut for CastableFactory +where + Args: 'static, + ReturnInterface: 'static + ?Sized, +{ + extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output + { + self.call(args) + } +} + +impl FnOnce for CastableFactory +where + Args: 'static, + ReturnInterface: 'static + ?Sized, +{ + type Output = InterfacePtr; + + extern "rust-call" fn call_once(self, args: Args) -> Self::Output + { + self.call(args) + } +} + +impl AnyFactory for CastableFactory +where + Args: 'static, + ReturnInterface: 'static + ?Sized, +{ +} -- cgit v1.2.3-18-g5258