@@ -33,29 +33,13 @@ use crate::{Error, INTERNAL_ERROR_MSG};
3333#[ cfg( debug_assertions) ]
3434use crate :: builder:: debug_asserts:: assert_app;
3535
36- // Allows DeferFn to implement Clone but remain object safe
36+ /// Allows [` DeferFn`] to implement [` Clone`]
3737// see https://stackoverflow.com/a/30353928
38- trait CloneDynFn : FnOnce ( Command ) -> Command + Send + Sync {
39- fn clone_in_box ( & self ) -> Box < dyn CloneDynFn > ;
40- }
41-
42- impl < F > CloneDynFn for F
43- where
44- F : FnOnce ( Command ) -> Command + Send + Sync + ' static + Clone ,
45- {
46- #[ inline( always) ]
47- fn clone_in_box ( & self ) -> Box < dyn CloneDynFn > {
48- Box :: new ( self . clone ( ) )
49- }
50- }
51-
52- impl Clone for Box < dyn CloneDynFn > {
53- #[ inline( always) ]
54- fn clone ( & self ) -> Box < dyn CloneDynFn > {
55- self . clone_in_box ( )
56- }
57- }
38+ trait CloneDynFn : dyn_clone:: DynClone + FnOnce ( Command ) -> Command + Send + Sync { }
39+ impl < F > CloneDynFn for F where F : dyn_clone:: DynClone + FnOnce ( Command ) -> Command + Send + Sync { }
40+ dyn_clone:: clone_trait_object!( CloneDynFn ) ;
5841
42+ /// Wraps a function that when called will update a [`Command`] object.
5943#[ derive( Clone ) ]
6044struct DeferFn ( Box < dyn CloneDynFn > ) ;
6145
@@ -87,7 +71,7 @@ impl DeferFn {
8771 }
8872}
8973
90- impl core :: fmt:: Debug for DeferFn {
74+ impl fmt:: Debug for DeferFn {
9175 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
9276 f. debug_tuple ( "DeferFn" ) . field ( & ".." ) . finish ( )
9377 }
0 commit comments