From 86bb94e37315f1808fba7e605b19099a7154d014 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Thu, 20 Apr 2023 17:10:32 +0100 Subject: [PATCH] not working --- src/main.rs | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3b6259c..966cf04 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,15 +3,15 @@ use std::sync::*; pub trait Callable: Any { type Output; - fn callable_call(self, a: Args) -> Self::Output; + fn curry_fn() -> fn(Self, Args) -> Self::Output; } impl Callable<(A,)> for F where F: Fn(A) -> O + 'static { type Output = O; - fn callable_call(self, (a,): (A,)) -> O { (self)(a) } + fn curry_fn() -> fn(Self, (A,)) -> O { |self_, (a,)| (self_)(a) } } impl Callable<(A,B)> for F where F: Fn(A,B) -> O + 'static { type Output = O; - fn callable_call(self, (a,b): (A,B)) -> O { (self)(a,b) } + fn curry_fn() -> fn(Self, (A,B)) -> O { |self_, (a,b)| (self_)(a,b) } } pub trait Object: Any + Send + Sync {} @@ -20,13 +20,17 @@ pub trait MI: Any { fn o_ti(&self) -> TypeId { TypeId::of::() } fn call(&self, o: Arc, u: ()) -> usize; } -/* -impl MI for fn(Arc) -> usize { - fn o_ti(&self) -> TypeId { TypeId::of::() } - fn call(&self, o: Arc) -> usize { - (self)(Arc::downcast(o).unwrap()) + +impl MI for fn((Arc,())) -> usize { + fn call(&self, o: Arc, u: ()) -> usize { + (self)((Arc::downcast(o).unwrap(), u)) } -}*/ +} +impl MI for fn((Arc,)) -> usize { + fn call(&self, o: Arc, _u: ()) -> usize { + (self)((Arc::downcast(o).unwrap(),)) + } +} fn example(o: Arc) -> usize { o.len() } @@ -61,11 +65,13 @@ where C: Fn((O,)) -> usize } */ fn main() { - const CL: () = { - |t| Callable::callable_call(example, t); - () + const CL: &dyn Any = { + &( + (&|t| Callable::curry_fn()(example, t)) + as fn(_) -> _ + ) }; -//example.callable_call(); +//example.curry_fn(); // let v: &dyn MI = k(example); println!("Hello, world!"); -- 2.30.2