diff options
author | HampusM <hampus@hampusmat.com> | 2022-08-29 20:52:56 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-08-29 21:01:32 +0200 |
commit | 080cc42bb1da09059dbc35049a7ded0649961e0c (patch) | |
tree | 307ee564124373616022c1ba2b4d5af80845cd92 /src/castable_factory/blocking.rs | |
parent | 6e31d8f9e46fece348f329763b39b9c6f2741c07 (diff) |
feat: implement async functionality
Diffstat (limited to 'src/castable_factory/blocking.rs')
-rw-r--r-- | src/castable_factory/blocking.rs | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/castable_factory/blocking.rs b/src/castable_factory/blocking.rs new file mode 100644 index 0000000..5ff4db0 --- /dev/null +++ b/src/castable_factory/blocking.rs @@ -0,0 +1,74 @@ +use crate::interfaces::any_factory::AnyFactory; +use crate::interfaces::factory::IFactory; +use crate::ptr::TransientPtr; + +pub struct CastableFactory<Args, ReturnInterface> +where + Args: 'static, + ReturnInterface: 'static + ?Sized, +{ + func: &'static dyn Fn<Args, Output = TransientPtr<ReturnInterface>>, +} + +impl<Args, ReturnInterface> CastableFactory<Args, ReturnInterface> +where + Args: 'static, + ReturnInterface: 'static + ?Sized, +{ + pub fn new( + func: &'static dyn Fn<Args, Output = TransientPtr<ReturnInterface>>, + ) -> Self + { + Self { func } + } +} + +impl<Args, ReturnInterface> IFactory<Args, ReturnInterface> + for CastableFactory<Args, ReturnInterface> +where + Args: 'static, + ReturnInterface: 'static + ?Sized, +{ +} + +impl<Args, ReturnInterface> Fn<Args> for CastableFactory<Args, ReturnInterface> +where + Args: 'static, + ReturnInterface: 'static + ?Sized, +{ + extern "rust-call" fn call(&self, args: Args) -> Self::Output + { + self.func.call(args) + } +} + +impl<Args, ReturnInterface> FnMut<Args> for CastableFactory<Args, ReturnInterface> +where + Args: 'static, + ReturnInterface: 'static + ?Sized, +{ + extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output + { + self.call(args) + } +} + +impl<Args, ReturnInterface> FnOnce<Args> for CastableFactory<Args, ReturnInterface> +where + Args: 'static, + ReturnInterface: 'static + ?Sized, +{ + type Output = TransientPtr<ReturnInterface>; + + extern "rust-call" fn call_once(self, args: Args) -> Self::Output + { + self.call(args) + } +} + +impl<Args, ReturnInterface> AnyFactory for CastableFactory<Args, ReturnInterface> +where + Args: 'static, + ReturnInterface: 'static + ?Sized, +{ +} |