@@ -179,7 +179,7 @@ pub async fn apply_effects(source: impl CollectiblesSource) -> Result<()> {
179
179
}
180
180
let span = tracing:: info_span!( "apply effects" , count = effects. len( ) ) ;
181
181
APPLY_EFFECT_CONTEXT
182
- . scope ( Mutex :: new ( ApplyEffectContext :: new ( ) ) , async move {
182
+ . scope ( Default :: default ( ) , async move {
183
183
// Limit the concurrency of effects
184
184
futures:: stream:: iter ( effects)
185
185
. map ( Ok )
@@ -263,7 +263,7 @@ impl Effects {
263
263
pub async fn apply ( & self ) -> Result < ( ) > {
264
264
let span = tracing:: info_span!( "apply effects" , count = self . effects. len( ) ) ;
265
265
APPLY_EFFECT_CONTEXT
266
- . scope ( Mutex :: new ( ApplyEffectContext :: new ( ) ) , async move {
266
+ . scope ( Default :: default ( ) , async move {
267
267
// Limit the concurrency of effects
268
268
futures:: stream:: iter ( self . effects . iter ( ) )
269
269
. map ( Ok )
@@ -282,20 +282,15 @@ task_local! {
282
282
static APPLY_EFFECT_CONTEXT : Mutex <ApplyEffectContext >;
283
283
}
284
284
285
+ #[ derive( Default ) ]
285
286
pub struct ApplyEffectContext {
286
287
data : FxHashMap < TypeId , Box < dyn Any + Send + Sync > > ,
287
288
}
288
289
289
290
impl ApplyEffectContext {
290
- pub fn new ( ) -> Self {
291
- Self {
292
- data : FxHashMap :: default ( ) ,
293
- }
294
- }
295
-
296
291
fn with_context < T , F : FnOnce ( & mut Self ) -> T > ( f : F ) -> T {
297
292
APPLY_EFFECT_CONTEXT
298
- . try_with ( |context| f ( & mut * context. lock ( ) ) )
293
+ . try_with ( |context| f ( & mut context. lock ( ) ) )
299
294
. expect ( "No effect context found" )
300
295
}
301
296
@@ -325,8 +320,7 @@ impl ApplyEffectContext {
325
320
Self :: with_context ( |context| {
326
321
let value = context. data . entry ( TypeId :: of :: < T > ( ) ) . or_insert_with ( || {
327
322
let value = insert_with ( ) ;
328
- let value = Box :: new ( value) ;
329
- value
323
+ Box :: new ( value)
330
324
} ) ;
331
325
f (
332
326
// Safety: the map is keyed by TypeId
0 commit comments