summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcel Müller <m.mueller@ifm.com>2022-05-12 09:29:28 +0200
committerMarcel Müller <m.mueller@ifm.com>2022-05-31 09:37:54 +0200
commit38e3c0abefb82a3d0bbb54ae3132aac920b15b25 (patch)
tree87491eba62e0623dc7479c4b750f4da1d7d09567
parent031832c6f22156694f0822265c5dd7b3b9683b9d (diff)
Move Message to message.rs
Signed-off-by: Marcel Müller <m.mueller@ifm.com>
-rw-r--r--crates/core/tedge_api/examples/heartbeat.rs4
-rw-r--r--crates/core/tedge_api/examples/universal_log.rs4
-rw-r--r--crates/core/tedge_api/src/address.rs5
-rw-r--r--crates/core/tedge_api/src/lib.rs4
-rw-r--r--crates/core/tedge_api/src/message.rs27
-rw-r--r--crates/core/tedge_api/src/plugin.rs34
6 files changed, 39 insertions, 39 deletions
diff --git a/crates/core/tedge_api/examples/heartbeat.rs b/crates/core/tedge_api/examples/heartbeat.rs
index 654c4311..b253009b 100644
--- a/crates/core/tedge_api/examples/heartbeat.rs
+++ b/crates/core/tedge_api/examples/heartbeat.rs
@@ -4,8 +4,8 @@ use async_trait::async_trait;
use futures::FutureExt;
use tedge_api::{
address::ReplySenderFor,
- message::MessageType,
- plugin::{AcceptsReplies, BuiltPlugin, Handle, Message, PluginDeclaration, PluginExt},
+ message::{AcceptsReplies, Message, MessageType},
+ plugin::{BuiltPlugin, Handle, PluginDeclaration, PluginExt},
Address, CancellationToken, Plugin, PluginBuilder, PluginConfiguration, PluginDirectory,
PluginError,
};
diff --git a/crates/core/tedge_api/examples/universal_log.rs b/crates/core/tedge_api/examples/universal_log.rs
index 82ff3130..34090040 100644
--- a/crates/core/tedge_api/examples/universal_log.rs
+++ b/crates/core/tedge_api/examples/universal_log.rs
@@ -4,8 +4,8 @@ use async_trait::async_trait;
use futures::FutureExt;
use tedge_api::{
address::ReplySenderFor,
- message::{AnyMessage, MessageType},
- plugin::{AnyMessages, BuiltPlugin, Handle, Message, PluginDeclaration, PluginExt},
+ message::{AnyMessage, Message, MessageType},
+ plugin::{AnyMessages, BuiltPlugin, Handle, PluginDeclaration, PluginExt},
Address, CancellationToken, Plugin, PluginBuilder, PluginConfiguration, PluginDirectory,
PluginError,
};
diff --git a/crates/core/tedge_api/src/address.rs b/crates/core/tedge_api/src/address.rs
index 4f786ea5..47b2fdea 100644
--- a/crates/core/tedge_api/src/address.rs
+++ b/crates/core/tedge_api/src/address.rs
@@ -5,8 +5,7 @@ use tokio::sync::RwLock;
use tracing::{instrument, trace};
use crate::{
- message::MessageType,
- plugin::{AcceptsReplies, Message},
+ message::{Message, MessageType, AcceptsReplies},
};
#[doc(hidden)]
@@ -410,7 +409,7 @@ mod tests {
use crate::{
address::{InnerMessageSender, ReplyReceiverFor, ReplySenderFor},
make_receiver_bundle,
- plugin::{AcceptsReplies, Message},
+ message::{AcceptsReplies, Message},
Address,
};
diff --git a/crates/core/tedge_api/src/lib.rs b/crates/core/tedge_api/src/lib.rs
index 5a9f77bb..758c33aa 100644
--- a/crates/core/tedge_api/src/lib.rs
+++ b/crates/core/tedge_api/src/lib.rs
@@ -8,7 +8,7 @@
/// All the parts required to write a plugin
pub mod plugin;
-pub use plugin::{Message, Plugin, PluginBuilder, PluginConfiguration, PluginDirectory, PluginExt};
+pub use plugin::{Plugin, PluginBuilder, PluginConfiguration, PluginDirectory, PluginExt};
/// Generic representation of a configuration
pub mod config;
@@ -24,7 +24,7 @@ pub use error::PluginError;
/// Predefined messages
pub mod message;
-pub use message::CoreMessages;
+pub use message::{Message, CoreMessages};
/// Cancellation token used by `tedge_api`
///
diff --git a/crates/core/tedge_api/src/message.rs b/crates/core/tedge_api/src/message.rs
index 3e4a6249..7fe1fc1a 100644
--- a/crates/core/tedge_api/src/message.rs
+++ b/crates/core/tedge_api/src/message.rs
@@ -1,6 +1,31 @@
+use downcast_rs::{impl_downcast, DowncastSync};
use serde::Serialize;
-use crate::{address::AnyMessageBox, plugin::Message};
+use crate::address::AnyMessageBox;
+
+/// An object that can be sent between [`Plugin`]s
+///
+/// This trait is a marker trait for all types that can be used as messages which can be sent
+/// between plugins in thin-edge.
+pub trait Message: Send + std::fmt::Debug + DynMessage + DowncastSync + 'static {}
+
+impl_downcast!(sync Message);
+
+/// A bag of messages making it easier to work with dynamic messages
+pub trait DynMessage {
+ /// Get the type name of this message
+ fn type_name(&self) -> &'static str {
+ std::any::type_name::<Self>()
+ }
+}
+
+impl<M: 'static> DynMessage for M {}
+
+/// Register that the [`Message`] can receive replies of kind `R`: [`Message`]
+pub trait AcceptsReplies: Message {
+ /// The reply type that can be sent to implementing messages as replies
+ type Reply: Message;
+}
/// A message that can contain any other message
///
diff --git a/crates/core/tedge_api/src/plugin.rs b/crates/core/tedge_api/src/plugin.rs
index 431127cf..1b3be154 100644
--- a/crates/core/tedge_api/src/plugin.rs
+++ b/crates/core/tedge_api/src/plugin.rs
@@ -15,7 +15,7 @@ use crate::{
address::{InternalMessage, ReceiverBundle, ReplySenderFor},
config::ConfigDescription,
error::{DirectoryError, PluginError},
- message::{CoreMessages, MessageType},
+ message::{CoreMessages, Message, MessageType},
Address,
};
@@ -99,7 +99,7 @@ pub trait PluginBuilder<PD: PluginDirectory>: Sync + Send + 'static {
///
/// #[derive(Debug)]
/// struct MyMessage;
- /// impl tedge_api::plugin::Message for MyMessage { }
+ /// impl tedge_api::Message for MyMessage { }
///
/// struct MyPluginBuilder;
/// struct MyPlugin; // + some impl Plugin for MyPlugin
@@ -220,7 +220,7 @@ pub trait PluginBuilder<PD: PluginDirectory>: Sync + Send + 'static {
///
/// #[derive(Debug)]
/// struct MyMessage;
- /// impl tedge_api::plugin::Message for MyMessage { }
+ /// impl tedge_api::Message for MyMessage { }
///
///
/// struct MyPluginBuilder;
@@ -387,7 +387,7 @@ impl HandleTypes {
/// #[derive(Debug)]
/// struct Heartbeat;
///
- /// impl tedge_api::plugin::Message for Heartbeat { }
+ /// impl tedge_api::Message for Heartbeat { }
///
/// struct HeartbeatPlugin;
///
@@ -436,30 +436,6 @@ impl HandleTypes {
}
}
-/// An object that can be sent between [`Plugin`]s
-///
-/// This trait is a marker trait for all types that can be used as messages which can be sent
-/// between plugins in thin-edge.
-pub trait Message: Send + std::fmt::Debug + DynMessage + DowncastSync + 'static {}
-
-impl_downcast!(sync Message);
-
-/// A bag of messages making it easier to work with dynamic messages
-pub trait DynMessage {
- /// Get the type name of this message
- fn type_name(&self) -> &'static str {
- std::any::type_name::<Self>()
- }
-}
-
-impl<M: 'static> DynMessage for M {}
-
-/// Register that the [`Message`] can receive replies of kind `R`: [`Message`]
-pub trait AcceptsReplies: Message {
- /// The reply type that can be sent to implementing messages as replies
- type Reply: Message;
-}
-
/// A bundle of messages
///
/// This trait is implemented on types that represent a bundle of different types of messages.
@@ -691,7 +667,7 @@ impl_does_handle_tuple!(M10 M9 M8 M7 M6 M5 M4 M3 M2 M1);
#[cfg(test)]
mod tests {
- use crate::{plugin::DynMessage, Message};
+ use crate::{message::DynMessage, Message};
use super::{Plugin, PluginBuilder};
use static_assertions::assert_obj_safe;