1
1
use std:: iter:: FromIterator ;
2
2
3
3
use include_dir:: Dir ;
4
+ use take_mut:: take;
4
5
5
6
use crate :: { loader:: from_directory, MigrationHook , Result , M } ;
6
7
@@ -42,14 +43,11 @@ impl<'u> MigrationsBuilder<'u> {
42
43
///
43
44
/// Panics if no migration with the `id` provided exists.
44
45
#[ must_use]
45
- pub fn edit ( mut self , id : usize , f : impl Fn ( & mut M ) ) -> Self {
46
+ pub fn edit ( mut self , id : usize , f : impl Fn ( M ) -> M ) -> Self {
46
47
if id < 1 {
47
48
panic ! ( "id cannot be equal to 0" ) ;
48
49
}
49
- f ( self
50
- . migrations
51
- . get_mut ( id - 1 )
52
- . expect ( "No migration with the given index" ) ) ;
50
+ take ( & mut self . migrations [ id - 1 ] , f) ;
53
51
self
54
52
}
55
53
@@ -76,8 +74,9 @@ impl<'u> M<'u> {
76
74
/// Use [`M::up_with_hook`] instead if you're creating a new migration.
77
75
/// This method is meant for editing existing transactions
78
76
/// when using the [`MigrationsBuilder`].
79
- pub fn set_up_hook ( & mut self , hook : impl MigrationHook + ' static ) {
77
+ pub fn set_up_hook ( mut self , hook : impl MigrationHook + ' static ) -> Self {
80
78
self . up_hook = Some ( hook. clone_box ( ) ) ;
79
+ self
81
80
}
82
81
83
82
/// Replace the `down_hook` in the given migration with the provided one.
@@ -87,7 +86,8 @@ impl<'u> M<'u> {
87
86
/// Use [`M::down_with_hook`] instead if you're creating a new migration.
88
87
/// This method is meant for editing existing transactions
89
88
/// when using the [`MigrationsBuilder`].
90
- pub fn set_down_hook ( & mut self , hook : impl MigrationHook + ' static ) {
89
+ pub fn set_down_hook ( mut self , hook : impl MigrationHook + ' static ) -> Self {
91
90
self . down_hook = Some ( hook. clone_box ( ) ) ;
91
+ self
92
92
}
93
93
}
0 commit comments