From 58e50e3d9073584064e13edf489fc008b0388149 Mon Sep 17 00:00:00 2001 From: HampusM Date: Tue, 19 Jul 2022 11:15:09 +0200 Subject: refactor: remove unused intertrait code --- syrette/src/libs/intertrait/mod.rs | 89 +--------------------- .../src/libs/intertrait_macros/gen_caster.rs | 2 - 2 files changed, 3 insertions(+), 88 deletions(-) diff --git a/syrette/src/libs/intertrait/mod.rs b/syrette/src/libs/intertrait/mod.rs index 3c7b27a..a3f24f1 100644 --- a/syrette/src/libs/intertrait/mod.rs +++ b/syrette/src/libs/intertrait/mod.rs @@ -16,10 +16,9 @@ use std::collections::HashMap; use std::rc::Rc; use std::sync::Arc; +use linkme::distributed_slice; use once_cell::sync::Lazy; -extern crate linkme; - mod hasher; use hasher::BuildFastHasher; @@ -29,7 +28,7 @@ pub mod cast_rc; pub type BoxedCaster = Box; -#[linkme::distributed_slice] +#[distributed_slice] pub static CASTERS: [fn() -> (TypeId, BoxedCaster)] = [..]; static CASTER_MAP: Lazy> = @@ -45,14 +44,6 @@ static CASTER_MAP: Lazy> pub struct Caster { - /// Casts an immutable reference to a trait object for `Any` to a reference - /// to a trait object for trait `T`. - pub cast_ref: fn(from: &dyn Any) -> &T, - - /// Casts a mutable reference to a trait object for `Any` to a mutable reference - /// to a trait object for trait `T`. - pub cast_mut: fn(from: &mut dyn Any) -> &mut T, - /// Casts a `Box` holding a trait object for `Any` to another `Box` holding a trait object /// for trait `T`. pub cast_box: fn(from: Box) -> Box, @@ -65,33 +56,11 @@ pub struct Caster impl Caster { pub fn new( - cast_ref: fn(from: &dyn Any) -> &T, - cast_mut: fn(from: &mut dyn Any) -> &mut T, - cast_box: fn(from: Box) -> Box, - cast_rc: fn(from: Rc) -> Rc, - ) -> Caster - { - Caster:: { - cast_ref, - cast_mut, - cast_box, - cast_rc, - } - } - - pub fn new_sync( - cast_ref: fn(from: &dyn Any) -> &T, - cast_mut: fn(from: &mut dyn Any) -> &mut T, cast_box: fn(from: Box) -> Box, cast_rc: fn(from: Rc) -> Rc, ) -> Caster { - Caster:: { - cast_ref, - cast_mut, - cast_box, - cast_rc, - } + Caster:: { cast_box, cast_rc } } } @@ -116,12 +85,6 @@ fn caster(type_id: TypeId) -> Option<&'static Caster> /// ``` pub trait CastFrom: Any + 'static { - /// Returns a immutable reference to `Any`, which is backed by the type implementing this trait. - fn ref_any(&self) -> &dyn Any; - - /// Returns a mutable reference to `Any`, which is backed by the type implementing this trait. - fn mut_any(&mut self) -> &mut dyn Any; - /// Returns a `Box` of `Any`, which is backed by the type implementing this trait. fn box_any(self: Box) -> Box; @@ -136,16 +99,6 @@ pub trait CastFromSync: CastFrom + Sync + Send + 'static impl CastFrom for T { - fn ref_any(&self) -> &dyn Any - { - self - } - - fn mut_any(&mut self) -> &mut dyn Any - { - self - } - fn box_any(self: Box) -> Box { self @@ -159,16 +112,6 @@ impl CastFrom for T impl CastFrom for dyn Any + 'static { - fn ref_any(&self) -> &dyn Any - { - self - } - - fn mut_any(&mut self) -> &mut dyn Any - { - self - } - fn box_any(self: Box) -> Box { self @@ -180,26 +123,8 @@ impl CastFrom for dyn Any + 'static } } -impl CastFromSync for T -{ - fn arc_any(self: Arc) -> Arc - { - self - } -} - impl CastFrom for dyn Any + Sync + Send + 'static { - fn ref_any(&self) -> &dyn Any - { - self - } - - fn mut_any(&mut self) -> &mut dyn Any - { - self - } - fn box_any(self: Box) -> Box { self @@ -210,11 +135,3 @@ impl CastFrom for dyn Any + Sync + Send + 'static self } } - -impl CastFromSync for dyn Any + Sync + Send + 'static -{ - fn arc_any(self: Arc) -> Arc - { - self - } -} diff --git a/syrette_macros/src/libs/intertrait_macros/gen_caster.rs b/syrette_macros/src/libs/intertrait_macros/gen_caster.rs index a0e63b5..213a75e 100644 --- a/syrette_macros/src/libs/intertrait_macros/gen_caster.rs +++ b/syrette_macros/src/libs/intertrait_macros/gen_caster.rs @@ -28,8 +28,6 @@ pub fn generate_caster(ty: &impl ToTokens, trait_: &impl ToTokens) -> TokenStrea let new_caster = quote! { syrette::libs::intertrait::Caster::::new( - |from| from.downcast_ref::<#ty>().unwrap(), - |from| from.downcast_mut::<#ty>().unwrap(), |from| from.downcast::<#ty>().unwrap(), |from| from.downcast::<#ty>().unwrap(), ) -- cgit v1.2.3-18-g5258