Skip to content

Commit

Permalink
revert: switch style back to rust stable
Browse files Browse the repository at this point in the history
  • Loading branch information
GregoryConrad committed Nov 30, 2023
1 parent 235be6b commit 4427dd0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
25 changes: 12 additions & 13 deletions rearch-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,18 @@ pub fn generate_tuple_side_effect_impl(input: TokenStream) -> TokenStream {
.map(|ident| format_ident!("{ident}"))
.collect::<Vec<_>>();
let once_cell_inits = (0..types.len()).map(|_| quote! { OnceCell::new() });
let individual_apis =
(0..types.len()).map(syn::Index::from).map(|i| {
quote! {
self.#i.build(SideEffectRegistrar::new(&mut all_states.#i, {
let rebuild_all = rebuild_all.clone();
Box::new(move |mutation: Box<dyn FnOnce(&mut Box<dyn Any + Send>)>| {
rebuild_all(Box::new(move |all_states| {
mutation(all_states.#i.get_mut().expect(EFFECT_FAILED_CAST_MSG));
}));
})
}))
}
});
let individual_apis = (0..types.len()).map(syn::Index::from).map(|i| {
quote! {
self.#i.build(SideEffectRegistrar::new(&mut all_states.#i, {
let rebuild_all = rebuild_all.clone();
Box::new(move |mutation: Box<dyn FnOnce(&mut Box<dyn Any + Send>)>| {
rebuild_all(Box::new(move |all_states| {
mutation(all_states.#i.get_mut().expect(EFFECT_FAILED_CAST_MSG));
}));
})
}))
}
});
let effect_impl = quote! {
impl<'a, #(#types: SideEffect<'a>),*> SideEffect<'a> for (#(#types),*) {
type Api = (#(#types::Api),*);
Expand Down
17 changes: 8 additions & 9 deletions rearch/src/side_effect_registrar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,14 @@ impl<'a> SideEffectRegistrar<'a> {
.expect(PREVIOUS_INIT_FAILED_MSG)
.downcast_mut::<T>()
.unwrap_or_else(|| panic!("{}", EFFECT_FAILED_CAST_MSG));
let rebuild =
move |mutation: Box<dyn FnOnce(&mut T)>| {
(self.rebuilder)(Box::new(|data| {
let data = data
.downcast_mut::<T>()
.unwrap_or_else(|| panic!("{}", EFFECT_FAILED_CAST_MSG));
mutation(data);
}));
};
let rebuild = move |mutation: Box<dyn FnOnce(&mut T)>| {
(self.rebuilder)(Box::new(|data| {
let data = data
.downcast_mut::<T>()
.unwrap_or_else(|| panic!("{}", EFFECT_FAILED_CAST_MSG));
mutation(data);
}));
};
(data, rebuild)
}
}
Expand Down
9 changes: 4 additions & 5 deletions rearch/src/side_effects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,10 @@ where
move |register: SideEffectRegistrar<'a>| {
let (state, set_state) = register.register(lazy_state(read));
let write = Arc::new(write);
let persist =
move |new_data| {
let persist_result = write(new_data);
set_state(persist_result);
};
let persist = move |new_data| {
let persist_result = write(new_data);
set_state(persist_result);
};
(&*state, persist)
}
}

0 comments on commit 4427dd0

Please sign in to comment.