summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@ifm.com>2022-09-11 12:11:53 +0200
committerMatthias Beyer <matthias.beyer@ifm.com>2022-09-11 12:11:53 +0200
commitc188eaa2e16c3778b827f5218191932a8560c682 (patch)
tree219399e54c71f1e8f173fa78edc78aa67367f797
parent96bfee68c0b2205b1fad7b10cd3236c80334dfde (diff)
Refactor: Pass closure to helperpost-merge/plugin-fdman
Signed-off-by: Matthias Beyer <matthias.beyer@ifm.com>
-rw-r--r--plugins/plugin_fdman/src/plugin.rs58
1 files changed, 26 insertions, 32 deletions
diff --git a/plugins/plugin_fdman/src/plugin.rs b/plugins/plugin_fdman/src/plugin.rs
index 2d2fa008..16fe362c 100644
--- a/plugins/plugin_fdman/src/plugin.rs
+++ b/plugins/plugin_fdman/src/plugin.rs
@@ -62,18 +62,16 @@ impl Handle<OpenOptions> for FdManPlugin {
message: OpenOptions,
sender: tedge_api::address::ReplySenderFor<OpenOptions>,
) -> Result<(), PluginError> {
- async fn inner(guard: Guard, message: OpenOptions) -> OpenOptionsResult {
- let file_result = message
- .as_std()
- .open(message.path())
- .map(|file| crate::file::FileGuard::new(file, guard))
- .map_err(Error::from)
- .map_err(OpenOptionsError::from);
- OpenOptionsResult::new(message, file_result)
- }
-
HandleWithGuard::new(self, message, sender)
- .with_handles(1, inner)
+ .with_handles(1, move |guard: Guard, message: OpenOptions| async {
+ let file_result = message
+ .as_std()
+ .open(message.path())
+ .map(|file| crate::file::FileGuard::new(file, guard))
+ .map_err(Error::from)
+ .map_err(OpenOptionsError::from);
+ OpenOptionsResult::new(message, file_result)
+ })
.await
}
}
@@ -85,17 +83,15 @@ impl Handle<Copy> for FdManPlugin {
message: Copy,
sender: tedge_api::address::ReplySenderFor<Copy>,
) -> Result<(), PluginError> {
- async fn inner(guard: Guard, message: Copy) -> CopyResult {
- let copy_res = tokio::fs::copy(message.src(), message.dst())
- .await
- .map_err(Error::from)
- .map_err(CopyError::from);
- drop(guard); // We can now drop the guard, as the copy process is done
- CopyResult::new(message, copy_res)
- }
-
HandleWithGuard::new(self, message, sender)
- .with_handles(2, inner)
+ .with_handles(2, move |guard: Guard, message: Copy| async {
+ let copy_res = tokio::fs::copy(message.src(), message.dst())
+ .await
+ .map_err(Error::from)
+ .map_err(CopyError::from);
+ drop(guard); // We can now drop the guard, as the copy process is done
+ CopyResult::new(message, copy_res)
+ })
.await
}
}
@@ -107,17 +103,15 @@ impl Handle<Rename> for FdManPlugin {
message: Rename,
sender: tedge_api::address::ReplySenderFor<Rename>,
) -> Result<(), PluginError> {
- async fn inner(guard: Guard, message: Rename) -> RenameResult {
- let rename_res = tokio::fs::rename(message.src(), message.dst())
- .await
- .map_err(Error::from)
- .map_err(RenameError::from);
- drop(guard); // We can now drop the guard, as the copy process is done
- RenameResult::new(message, rename_res)
- }
-
HandleWithGuard::new(self, message, sender)
- .with_handles(2, inner)
+ .with_handles(2, move |guard: Guard, message: Rename| async {
+ let rename_res = tokio::fs::rename(message.src(), message.dst())
+ .await
+ .map_err(Error::from)
+ .map_err(RenameError::from);
+ drop(guard); // We can now drop the guard, as the copy process is done
+ RenameResult::new(message, rename_res)
+ })
.await
}
}
@@ -159,7 +153,7 @@ where
async fn with_handles<F, Fut>(self, handles_to_aquire: u64, fun: F) -> Result<(), PluginError>
where
- F: Fn(Guard, M) -> Fut,
+ F: FnOnce(Guard, M) -> Fut,
Fut: std::future::Future<Output = Res>,
{
match self.plugin.aquire_handles(handles_to_aquire) {