@@ -514,7 +514,7 @@ impl Rocket<Build> {
514
514
/// If multiple instances of the same type of Fairing have been attached, the modify function
515
515
/// will be run on each instance.
516
516
#[ must_use]
517
- pub fn modify_fairings < F : Fairing , E : fmt:: Debug > ( mut self , modifier : impl Fn ( & mut F ) -> Result < ( ) , E > ) -> Result < Self , Self > {
517
+ pub fn modify_fairings < F : Fairing , E : fmt:: Debug > ( mut self , mut modifier : impl FnMut ( & mut F ) -> Result < ( ) , E > ) -> Result < Self , Self > {
518
518
#[ derive( Debug , PartialEq , Eq ) ]
519
519
enum State {
520
520
None ,
@@ -523,16 +523,11 @@ impl Rocket<Build> {
523
523
}
524
524
let mut state = State :: None ;
525
525
for f in self . fairings . iter_mut ( ) {
526
- let f = f. as_mut ( ) ;
527
- if f. type_id ( ) == TypeId :: of :: < F > ( ) {
528
- // SAFTEY: `f` is a valid pointer since it was obtained from a Box, and it points
529
- // at an `F` since it has the same TypeId. Converting from dyn type to a concrete
530
- // type is handled automatically by the compilier
531
- let f = unsafe { & mut * ( ( f as * mut dyn Fairing ) as * mut F ) } ;
526
+ if let Some ( f) = f. as_any_mut ( ) . downcast_mut ( ) {
532
527
match modifier ( f) {
533
528
Ok ( ( ) ) => if state == State :: None { state = State :: Success } ,
534
- Err ( e ) => {
535
- error_ ! ( "Failed to modify fairing: {:?}" , e ) ;
529
+ Err ( error ) => {
530
+ error ! ( ?error , "Failed to modify fairing" ) ;
536
531
state = State :: Failure ;
537
532
}
538
533
}
0 commit comments