summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@ifm.com>2022-09-11 11:56:11 +0200
committerMatthias Beyer <matthias.beyer@ifm.com>2022-09-11 11:56:27 +0200
commite1b3e09371f18214e6cca9fbe93d7b7689d19174 (patch)
tree60e12452abe301ee63a6631cb1fca7af1124c642
parentff51394068b06a9834b0dda0874c56da981e94e7 (diff)
Refactor: Make all result types impl MessageResult trait
This way we can use the result types in a generic implementation to refactor the Handle<> implementations for the Plugin itself. Signed-off-by: Matthias Beyer <matthias.beyer@ifm.com>
-rw-r--r--plugins/plugin_fdman/src/message/copy.rs10
-rw-r--r--plugins/plugin_fdman/src/message/mod.rs8
-rw-r--r--plugins/plugin_fdman/src/message/open_options.rs19
-rw-r--r--plugins/plugin_fdman/src/message/rename.rs10
4 files changed, 29 insertions, 18 deletions
diff --git a/plugins/plugin_fdman/src/message/copy.rs b/plugins/plugin_fdman/src/message/copy.rs
index c57ede30..adb5726a 100644
--- a/plugins/plugin_fdman/src/message/copy.rs
+++ b/plugins/plugin_fdman/src/message/copy.rs
@@ -37,10 +37,6 @@ pub struct CopyResult {
}
impl CopyResult {
- pub(crate) fn new(copy: Copy, result: Result<u64, CopyError>) -> Self {
- Self { copy, result }
- }
-
pub fn copy(&self) -> &Copy {
&self.copy
}
@@ -50,6 +46,12 @@ impl CopyResult {
}
}
+impl crate::message::MessageResult<Copy, u64, CopyError> for CopyResult {
+ fn new(copy: Copy, result: Result<u64, CopyError>) -> Self {
+ Self { copy, result }
+ }
+}
+
impl Message for CopyResult {}
#[derive(Debug, thiserror::Error)]
diff --git a/plugins/plugin_fdman/src/message/mod.rs b/plugins/plugin_fdman/src/message/mod.rs
index 32e11302..4e1828cb 100644
--- a/plugins/plugin_fdman/src/message/mod.rs
+++ b/plugins/plugin_fdman/src/message/mod.rs
@@ -6,3 +6,11 @@ pub use self::rename::*;
mod open_options;
pub use self::open_options::*;
+
+pub(crate) trait MessageResult<M, T, E>
+where
+ M: tedge_api::Message,
+ E: std::error::Error,
+{
+ fn new(message: M, result: Result<T, E>) -> Self;
+}
diff --git a/plugins/plugin_fdman/src/message/open_options.rs b/plugins/plugin_fdman/src/message/open_options.rs
index 39cc926e..c6b12556 100644
--- a/plugins/plugin_fdman/src/message/open_options.rs
+++ b/plugins/plugin_fdman/src/message/open_options.rs
@@ -94,16 +94,6 @@ pub struct OpenOptionsResult {
}
impl OpenOptionsResult {
- pub(crate) fn new(
- open_options: OpenOptions,
- result: Result<FileGuard, OpenOptionsError>,
- ) -> Self {
- Self {
- open_options,
- result,
- }
- }
-
pub fn open_options(&self) -> &OpenOptions {
&self.open_options
}
@@ -117,4 +107,13 @@ impl OpenOptionsResult {
}
}
+impl crate::message::MessageResult<OpenOptions, FileGuard, OpenOptionsError> for OpenOptionsResult {
+ fn new(open_options: OpenOptions, result: Result<FileGuard, OpenOptionsError>) -> Self {
+ Self {
+ open_options,
+ result,
+ }
+ }
+}
+
impl Message for OpenOptionsResult {}
diff --git a/plugins/plugin_fdman/src/message/rename.rs b/plugins/plugin_fdman/src/message/rename.rs
index da58928e..032a91db 100644
--- a/plugins/plugin_fdman/src/message/rename.rs
+++ b/plugins/plugin_fdman/src/message/rename.rs
@@ -37,10 +37,6 @@ pub struct RenameResult {
}
impl RenameResult {
- pub(crate) fn new(rename: Rename, result: Result<(), RenameError>) -> Self {
- Self { rename, result }
- }
-
pub fn rename(&self) -> &Rename {
&self.rename
}
@@ -50,6 +46,12 @@ impl RenameResult {
}
}
+impl crate::message::MessageResult<Rename, (), RenameError> for RenameResult {
+ fn new(rename: Rename, result: Result<(), RenameError>) -> Self {
+ Self { rename, result }
+ }
+}
+
impl Message for RenameResult {}
#[derive(Debug, thiserror::Error)]