@@ -179,7 +179,7 @@ pub async fn apply_effects(source: impl CollectiblesSource) -> Result<()> {
179179 }
180180 let span = tracing:: info_span!( "apply effects" , count = effects. len( ) ) ;
181181 APPLY_EFFECT_CONTEXT
182- . scope ( Mutex :: new ( ApplyEffectContext :: new ( ) ) , async move {
182+ . scope ( Default :: default ( ) , async move {
183183 // Limit the concurrency of effects
184184 futures:: stream:: iter ( effects)
185185 . map ( Ok )
@@ -263,7 +263,7 @@ impl Effects {
263263 pub async fn apply ( & self ) -> Result < ( ) > {
264264 let span = tracing:: info_span!( "apply effects" , count = self . effects. len( ) ) ;
265265 APPLY_EFFECT_CONTEXT
266- . scope ( Mutex :: new ( ApplyEffectContext :: new ( ) ) , async move {
266+ . scope ( Default :: default ( ) , async move {
267267 // Limit the concurrency of effects
268268 futures:: stream:: iter ( self . effects . iter ( ) )
269269 . map ( Ok )
@@ -282,20 +282,15 @@ task_local! {
282282 static APPLY_EFFECT_CONTEXT : Mutex <ApplyEffectContext >;
283283}
284284
285+ #[ derive( Default ) ]
285286pub struct ApplyEffectContext {
286287 data : FxHashMap < TypeId , Box < dyn Any + Send + Sync > > ,
287288}
288289
289290impl ApplyEffectContext {
290- pub fn new ( ) -> Self {
291- Self {
292- data : FxHashMap :: default ( ) ,
293- }
294- }
295-
296291 fn with_context < T , F : FnOnce ( & mut Self ) -> T > ( f : F ) -> T {
297292 APPLY_EFFECT_CONTEXT
298- . try_with ( |context| f ( & mut * context. lock ( ) ) )
293+ . try_with ( |context| f ( & mut context. lock ( ) ) )
299294 . expect ( "No effect context found" )
300295 }
301296
@@ -325,8 +320,7 @@ impl ApplyEffectContext {
325320 Self :: with_context ( |context| {
326321 let value = context. data . entry ( TypeId :: of :: < T > ( ) ) . or_insert_with ( || {
327322 let value = insert_with ( ) ;
328- let value = Box :: new ( value) ;
329- value
323+ Box :: new ( value)
330324 } ) ;
331325 f (
332326 // Safety: the map is keyed by TypeId
0 commit comments