Skip to content

Commit

Permalink
wip, lotable backed global state
Browse files Browse the repository at this point in the history
  • Loading branch information
o0Ignition0o committed Jun 24, 2021
1 parent 871ed16 commit 627646b
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/bastion/src/system/global_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,17 @@ impl GlobalState {
}

/// Applies a user-defined function that mutates inner data.
pub fn write<T: Send + Sync + 'static, F>(&mut self, mut func: F)
pub fn write<T: Send + Sync + 'static, F>(&mut self, func: F)
where
F: FnMut(&mut T) -> T,
F: Fn(&T) -> T,
{
self.table.get(&TypeId::of::<T>()).map(|container| {
match container.get().downcast_mut::<T>() {
Some(value) => container.replace_with(|_| {
container.get().downcast_ref::<T>().map(|value| {
container.replace_with(|_| {
let updated_value = func(value);
Box::new(updated_value)
}),
None => {}
}
})
})
});
}

Expand Down

0 comments on commit 627646b

Please sign in to comment.