From: Ian Jackson Date: Thu, 20 Apr 2023 15:20:06 +0000 (+0100) Subject: fromk play X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=b60c0ef2f29bc97669c12ee509e14aa497b94ab5;p=rust-experiments.git fromk play --- diff --git a/src/main.rs b/src/main.rs index 8525d77..9860f70 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,36 @@ +use std::any::*; +use std::sync::*; -mod private_outer { - mod private_inner_ref { - /// Consumes a `crate::private_outer::private_inner_def::Item`. - fn t(_: crate::private_outer::private_inner_def::Item) { } +pub trait Object: Any + Send + Sync {} +impl Object for String {} +pub trait MI { + fn o_ti(&self) -> TypeId; + fn call(&self, o: Arc) -> 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()) } +} - pub(super) mod private_inner_def { - pub(super) struct Item; - } +fn example(o: Arc) -> usize { o.len() } + +const fn k>(f: &F) -> &dyn MI + '_ { + move |o| f(o) + /* + struct TE(&F); + impl MI for TE { + fn o_ti(&self) -> TypeId { TypeId::of::() } + fn call(&self, o: Arc) -> usize { + + } + }*/ + +} + +fn main() { + let v: &dyn MI = k(&example); + + println!("Hello, world!"); }