diff options
author | HampusM <hampus@hampusmat.com> | 2022-07-19 11:15:09 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-07-19 11:15:09 +0200 |
commit | 58e50e3d9073584064e13edf489fc008b0388149 (patch) | |
tree | 49c7a77592d0a1ef670bb6723f28735175eefca9 | |
parent | 46196985639833eae6cceea48751efaeabf5600c (diff) |
refactor: remove unused intertrait code
-rw-r--r-- | syrette/src/libs/intertrait/mod.rs | 89 | ||||
-rw-r--r-- | syrette_macros/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<dyn Any + Send + Sync>; -#[linkme::distributed_slice] +#[distributed_slice] pub static CASTERS: [fn() -> (TypeId, BoxedCaster)] = [..]; static CASTER_MAP: Lazy<HashMap<(TypeId, TypeId), BoxedCaster, BuildFastHasher>> = @@ -45,14 +44,6 @@ static CASTER_MAP: Lazy<HashMap<(TypeId, TypeId), BoxedCaster, BuildFastHasher>> pub struct Caster<T: ?Sized + 'static> { - /// 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<dyn Any>) -> Box<T>, @@ -65,33 +56,11 @@ pub struct Caster<T: ?Sized + 'static> impl<T: ?Sized + 'static> Caster<T> { pub fn new( - cast_ref: fn(from: &dyn Any) -> &T, - cast_mut: fn(from: &mut dyn Any) -> &mut T, - cast_box: fn(from: Box<dyn Any>) -> Box<T>, - cast_rc: fn(from: Rc<dyn Any>) -> Rc<T>, - ) -> Caster<T> - { - Caster::<T> { - 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<dyn Any>) -> Box<T>, cast_rc: fn(from: Rc<dyn Any>) -> Rc<T>, ) -> Caster<T> { - Caster::<T> { - cast_ref, - cast_mut, - cast_box, - cast_rc, - } + Caster::<T> { cast_box, cast_rc } } } @@ -116,12 +85,6 @@ fn caster<T: ?Sized + 'static>(type_id: TypeId) -> Option<&'static Caster<T>> /// ``` 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<Self>) -> Box<dyn Any>; @@ -136,16 +99,6 @@ pub trait CastFromSync: CastFrom + Sync + Send + 'static impl<T: Sized + Any + 'static> CastFrom for T { - fn ref_any(&self) -> &dyn Any - { - self - } - - fn mut_any(&mut self) -> &mut dyn Any - { - self - } - fn box_any(self: Box<Self>) -> Box<dyn Any> { self @@ -159,16 +112,6 @@ impl<T: Sized + Any + 'static> 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<Self>) -> Box<dyn Any> { self @@ -180,26 +123,8 @@ impl CastFrom for dyn Any + 'static } } -impl<T: Sized + Sync + Send + 'static> CastFromSync for T -{ - fn arc_any(self: Arc<Self>) -> Arc<dyn Any + Sync + Send + 'static> - { - 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<Self>) -> Box<dyn Any> { 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<Self>) -> Arc<dyn Any + Sync + Send + 'static> - { - 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::<dyn #trait_>::new( - |from| from.downcast_ref::<#ty>().unwrap(), - |from| from.downcast_mut::<#ty>().unwrap(), |from| from.downcast::<#ty>().unwrap(), |from| from.downcast::<#ty>().unwrap(), ) |