File tree 1 file changed +5
-5
lines changed
crates/factors-derive/src
1 file changed +5
-5
lines changed Original file line number Diff line number Diff line change @@ -53,6 +53,7 @@ fn expand_factors(input: &DeriveInput) -> syn::Result<TokenStream> {
53
53
factor_types. push ( & field. ty ) ;
54
54
}
55
55
56
+ let Any = quote ! ( :: std:: any:: Any ) ;
56
57
let TypeId = quote ! ( :: std:: any:: TypeId ) ;
57
58
let factors_crate = format_ident ! ( "spin_factors" ) ;
58
59
let factors_path = quote ! ( :: #factors_crate) ;
@@ -146,11 +147,10 @@ fn expand_factors(input: &DeriveInput) -> syn::Result<TokenStream> {
146
147
type InstanceState = #state_name;
147
148
148
149
fn app_state<F : #Factor >( app_state: & Self :: AppState ) -> Option <& F :: AppState > {
149
- let type_id = #TypeId :: of:: <F >( ) ;
150
150
#(
151
- if type_id == # TypeId :: of :: <#factor_types> ( ) {
152
- unsafe {
153
- return Some ( :: std :: mem :: transmute ( & app_state . #factor_names ) ) ;
151
+ if let Some ( state ) = & app_state . #factor_names {
152
+ if let Some ( state ) = <dyn # Any > :: downcast_ref ( state ) {
153
+ return Some ( state )
154
154
}
155
155
}
156
156
) *
@@ -165,7 +165,7 @@ fn expand_factors(input: &DeriveInput) -> syn::Result<TokenStream> {
165
165
if type_id == #TypeId :: of:: <#factor_types>( ) {
166
166
return Some (
167
167
builders. #factor_names. as_mut( ) . map( |builder| {
168
- unsafe { :: std :: mem :: transmute ( builder) }
168
+ <dyn # Any > :: downcast_mut ( builder) . unwrap ( )
169
169
} )
170
170
) ;
171
171
}
You can’t perform that action at this time.
0 commit comments