Diffstat (limited to 'tests/common/builder.rs')
| -rw-r--r-- | tests/common/builder.rs | 65 |
1 files changed, 44 insertions, 21 deletions
diff --git a/tests/common/builder.rs b/tests/common/builder.rs index 7a07898..49f7d16 100644 --- a/tests/common/builder.rs +++ b/tests/common/builder.rs @@ -7,9 +7,10 @@ use effectful::{ }; use mockall::mock; use treaty::{ - any::{indirect, AnyTrait, AnyTraitObject, TypeNameId}, + any::{AnyTrait, MutAnyUnsized, WithLtTypeId}, + build::BuilderTypes, protocol::{AsVisitor, DynVisitor}, - Builder, BuilderTypes, + Builder, }; use crate::common::{ContextLock, StaticTypeMap}; @@ -32,8 +33,10 @@ mock! { pub fn from_seed(seed: Seed) -> Self; pub fn build(self) -> Result<Value, Error>; - pub fn traits(&self, id: TypeNameId) -> &Option<Box<DynamicShim<dyn for<'ctx> AnyTrait<'ctx, E>>>>; - pub fn traits_mut(&mut self, id: TypeNameId) -> &mut Option<Box<DynamicShim<dyn for<'ctx> AnyTrait<'ctx, E>>>>; + // pub fn traits(&self, id: WithLtTypeId<'_, '_>) -> &Option<Box<DynamicShim<dyn for<'ctx> AnyTrait<'ctx, E>>>>; + // pub fn traits_mut(&mut self, id: WithLtTypeId<'_, '_>) -> &mut Option<Box<DynamicShim<dyn for<'ctx> AnyTrait<'ctx, E>>>>; + + pub fn traits_mut(&mut self) -> &mut Box<dyn for<'a, 'ctx> FnMut(WithLtTypeId<'a, 'ctx>) -> Option<MutAnyUnsized<'a, 'a, 'ctx>>>; } } @@ -110,36 +113,56 @@ where } } -impl<'ctx, Seed, Value, Error, E: Environment> AnyTrait<'ctx, E> - for MockBuilder<Seed, Value, Error, E> +impl<'ctx, Seed, Value, Error, E: Environment> AnyTrait<'ctx> for MockBuilder<Seed, Value, Error, E> where Seed: DynBind<E>, Error: DynBind<E>, Dynamic<Value>: DynBind<E>, { - fn upcast_to_id<'a>( + fn upcast_by_id<'a, 'lt: 'a>( &'a self, - id: TypeNameId, - ) -> Option<AnyTraitObject<'a, 'ctx, indirect::Ref, E>> + id: treaty::any::WithLtTypeId<'lt, 'ctx>, + ) -> Option<treaty::any::RefAnyUnsized<'a, 'lt, 'ctx>> where - 'ctx: 'a, + 'ctx: 'lt, { - // Find the first trait handler that wants to upcast. - self.traits(id).as_ref().and_then(|t| t.0.upcast_to_id(id)) + let _id = id; + None } - fn upcast_to_id_mut<'a>( + fn upcast_by_id_mut<'a, 'lt: 'a>( &'a mut self, - id: TypeNameId, - ) -> Option<AnyTraitObject<'a, 'ctx, indirect::Mut, E>> + id: treaty::any::WithLtTypeId<'lt, 'ctx>, + ) -> Option<treaty::any::MutAnyUnsized<'a, 'lt, 'ctx>> where - 'ctx: 'a, + 'ctx: 'lt, { - // Find the first trait handler that wants to upcast. - self.traits_mut(id) - .as_mut() - .and_then(|t| t.0.upcast_to_id_mut(id)) + self.traits_mut()(id) } - type Available = () where Self: Sized; + // fn upcast_to_id<'a>( + // &'a self, + // id: TypeNameId, + // ) -> Option<AnyTraitObject<'a, 'ctx, indirect::Ref, E>> + // where + // 'ctx: 'a, + // { + // // Find the first trait handler that wants to upcast. + // self.traits(id).as_ref().and_then(|t| t.0.upcast_to_id(id)) + // } + // + // fn upcast_to_id_mut<'a>( + // &'a mut self, + // id: TypeNameId, + // ) -> Option<AnyTraitObject<'a, 'ctx, indirect::Mut, E>> + // where + // 'ctx: 'a, + // { + // // Find the first trait handler that wants to upcast. + // self.traits_mut(id) + // .as_mut() + // .and_then(|t| t.0.upcast_to_id_mut(id)) + // } + // + // type Available = () where Self: Sized; } |