summaryrefslogtreecommitdiffstats
path: root/crates
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@ifm.com>2022-03-22 15:08:42 +0100
committerMatthias Beyer <matthias.beyer@ifm.com>2022-03-22 15:08:42 +0100
commita1e93a5e82f0f551495dedd18e13992ee31d2e6a (patch)
tree33d0e34c07981032675410dae4f7eb827b788203 /crates
parentadab22a9aed60b3e3a091f4107df23eadf24d85f (diff)
Update doc for PluginBuilder
This patch updates the docs for the PluginBuilder type and adapts all doc tests to the new interfaces. Signed-off-by: Matthias Beyer <matthias.beyer@ifm.com>
Diffstat (limited to 'crates')
-rw-r--r--crates/core/tedge_api/src/plugin.rs70
1 files changed, 55 insertions, 15 deletions
diff --git a/crates/core/tedge_api/src/plugin.rs b/crates/core/tedge_api/src/plugin.rs
index 3e99997f..e3adb66e 100644
--- a/crates/core/tedge_api/src/plugin.rs
+++ b/crates/core/tedge_api/src/plugin.rs
@@ -93,14 +93,17 @@ pub trait PluginBuilder<PD: PluginDirectory>: Sync + Send + 'static {
/// # Example
///
/// ```no_run
- /// # use tedge_api::{Message, Plugin, plugin::{BuiltPlugin}, PluginConfiguration}
+ /// # use tedge_api::{Plugin, plugin::BuiltPlugin, PluginError, PluginDirectory, PluginBuilder, PluginConfiguration};
///
/// #[derive(Debug)]
/// struct MyMessage;
- /// impl Message for MyMessage {}
+ /// impl tedge_api::plugin::Message for MyMessage {
+ /// type Reply = tedge_api::message::NoReply;
+ /// }
///
/// struct MyPluginBuilder;
/// struct MyPlugin; // + some impl Plugin for MyPlugin
+ /// # #[async_trait::async_trait]
/// # impl Plugin for MyPlugin {
/// # async fn setup(&mut self) -> Result<(), PluginError> {
/// # unimplemented!()
@@ -110,16 +113,28 @@ pub trait PluginBuilder<PD: PluginDirectory>: Sync + Send + 'static {
/// # }
/// # }
///
- /// #[async_trait]
+ /// #[async_trait::async_trait]
+ /// impl tedge_api::plugin::Handle<MyMessage> for MyPlugin {
+ /// async fn handle_message(
+ /// &self,
+ /// message: MyMessage,
+ /// sender: tedge_api::address::ReplySender<tedge_api::message::NoReply>
+ /// ) -> Result<(), tedge_api::error::PluginError> {
+ /// // ... Do something with it
+ ///# Ok(())
+ /// }
+ /// }
+ ///
+ /// #[async_trait::async_trait]
/// impl<PD: PluginDirectory> PluginBuilder<PD> for MyPluginBuilder {
/// fn kind_message_types() -> tedge_api::plugin::HandleTypes
/// where
/// Self: Sized,
/// {
- /// HandleTypes::get_handlers_for::<(MyMessage,), MyPlugin>()
+ /// tedge_api::plugin::HandleTypes::declare_handlers_for::<(MyMessage,), MyPlugin>()
/// }
/// // other trait functions...
- /// # fn kind_name(&self) -> &'static str {
+ /// # fn kind_name() -> &'static str {
/// # unimplemented!()
/// # }
/// # async fn verify_configuration(
@@ -131,8 +146,9 @@ pub trait PluginBuilder<PD: PluginDirectory>: Sync + Send + 'static {
/// # async fn instantiate(
/// # &self,
/// # config: PluginConfiguration,
- /// # tedge_comms: &PD,
- /// # ) -> Result<BuiltPlugin, PluginError>
+ /// # cancellation_token: tedge_api::CancellationToken,
+ /// # core_comms: &PD,
+ /// # ) -> Result<BuiltPlugin, tedge_api::error::PluginError>
/// # where
/// # PD: 'async_trait,
/// # {
@@ -179,43 +195,67 @@ pub trait PluginBuilder<PD: PluginDirectory>: Sync + Send + 'static {
/// # Example
///
/// ```no_run
+ /// # use tedge_api::plugin::BuiltPlugin;
+ /// # use tedge_api::PluginConfiguration;
+ /// # use tedge_api::Plugin;
+ /// # use tedge_api::PluginBuilder;
+ /// # use tedge_api::PluginDirectory;
+ ///
/// #[derive(Debug)]
/// struct MyMessage;
- /// impl Message for MyMessage {}
+ /// impl tedge_api::plugin::Message for MyMessage {
+ /// type Reply = tedge_api::message::NoReply;
+ /// }
+ ///
///
/// struct MyPluginBuilder;
/// struct MyPlugin; // + some impl Plugin for MyPlugin
+ /// # #[async_trait::async_trait]
/// # impl Plugin for MyPlugin {
- /// # async fn setup(&mut self) -> Result<(), PluginError> {
+ /// # async fn setup(&mut self) -> Result<(), tedge_api::error::PluginError> {
/// # unimplemented!()
/// # }
- /// # async fn shutdown(&mut self) -> Result<(), PluginError> {
+ /// # async fn shutdown(&mut self) -> Result<(), tedge_api::error::PluginError> {
/// # unimplemented!()
/// # }
/// # }
///
- /// #[async_trait]
+ /// #[async_trait::async_trait]
+ /// impl tedge_api::plugin::Handle<MyMessage> for MyPlugin {
+ /// async fn handle_message(
+ /// &self,
+ /// _message: MyMessage,
+ /// _sender: tedge_api::address::ReplySender<tedge_api::message::NoReply>,
+ /// ) -> Result<(), tedge_api::error::PluginError> {
+ /// // implementation...
+ /// # unimplemented!()
+ /// }
+ /// }
+ ///
+ /// #[async_trait::async_trait]
/// impl<PD: PluginDirectory> PluginBuilder<PD> for MyPluginBuilder {
/// async fn instantiate(
/// &self,
/// config: PluginConfiguration,
- /// tedge_comms: &PD,
- /// ) -> Result<BuiltPlugin, PluginError>
+ /// cancellation_token: tedge_api::CancellationToken,
+ /// core_comms: &PD,
+ /// ) -> Result<BuiltPlugin, tedge_api::error::PluginError>
/// where
/// PD: 'async_trait,
/// {
+ /// use tedge_api::plugin::PluginExt;
/// let p = MyPlugin {};
/// Ok(p.into_untyped::<(MyMessage,)>())
/// }
/// // other trait functions...
- /// # fn kind_name(&self) -> &'static str {
+ /// # fn kind_name() -> &'static str {
/// # unimplemented!()
/// # }
/// # fn kind_message_types() -> tedge_api::plugin::HandleTypes
/// # where
/// # Self: Sized,
/// # {
- /// # HandleTypes::get_handlers_for::<(MyMessage,), MyPlugin>()
+ /// # tedge_api::plugin::HandleTypes::declare_handlers_for::<(MyMessage,), MyPlugin>()
/// # }
/// # async fn verify_configuration(
/// # &self,