diff options
author | Matthias Beyer <matthias.beyer@ifm.com> | 2022-06-23 12:36:11 +0200 |
---|---|---|
committer | Matthias Beyer <matthias.beyer@ifm.com> | 2022-06-23 16:42:57 +0200 |
commit | 10ef8e00bd7c78ed709c933edd92a59cc885e341 (patch) | |
tree | ce23d7f8b8a64aa1be8f42219892d5adafbb71b6 /crates/core/tedge_api | |
parent | 2d1b5a5353910dce8e785e2ffe3d2786d0917b2b (diff) |
Change TypeUuid implementation to bevy_reflect
This patch replaces the type_uuid crate with the bevy_reflect
implementation of the functionality.
The rationale for this is, that the implementation of the type_uuid
crate does not support generics, but the bevy_reflect implementation
does.
As we need generic support for type uuids, we change to bevy_reflect
here.
Suggested-by: Marcel Müller <m.mueller@ifm.com>
Signed-off-by: Matthias Beyer <matthias.beyer@ifm.com>
Diffstat (limited to 'crates/core/tedge_api')
-rw-r--r-- | crates/core/tedge_api/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/core/tedge_api/README.md | 4 | ||||
-rw-r--r-- | crates/core/tedge_api/examples/heartbeat.rs | 2 | ||||
-rw-r--r-- | crates/core/tedge_api/examples/universal_log.rs | 6 | ||||
-rw-r--r-- | crates/core/tedge_api/src/address.rs | 4 | ||||
-rw-r--r-- | crates/core/tedge_api/src/message.rs | 16 | ||||
-rw-r--r-- | crates/core/tedge_api/src/plugin.rs | 10 |
7 files changed, 22 insertions, 22 deletions
diff --git a/crates/core/tedge_api/Cargo.toml b/crates/core/tedge_api/Cargo.toml index a4ff92ab..06184c32 100644 --- a/crates/core/tedge_api/Cargo.toml +++ b/crates/core/tedge_api/Cargo.toml @@ -21,7 +21,7 @@ termimad = "0.20.1" nu-ansi-term = "0.45.1" tedge_config_derive = { version = "0.1.0", path = "tedge_config_derive" } tracing = "0.1" -type-uuid = "0.1.2" +bevy_reflect = "0.7.0" [dev-dependencies] pretty_assertions = "1.2.1" diff --git a/crates/core/tedge_api/README.md b/crates/core/tedge_api/README.md index 8c59231a..07a4a5bc 100644 --- a/crates/core/tedge_api/README.md +++ b/crates/core/tedge_api/README.md @@ -85,9 +85,9 @@ others. For example: ```rust -use tedge_api::{Message, TypeUuid}; +use tedge_api::Message; -#[derive(Debug, TypeUuid)] +#[derive(Debug, bevy_reflect::TypeUuid)] #[uuid = "b60dd50c-ccef-4204-b370-18bbbb68d6e2"] struct Value(f64); diff --git a/crates/core/tedge_api/examples/heartbeat.rs b/crates/core/tedge_api/examples/heartbeat.rs index 8d64232a..41dc7e74 100644 --- a/crates/core/tedge_api/examples/heartbeat.rs +++ b/crates/core/tedge_api/examples/heartbeat.rs @@ -1,6 +1,7 @@ use std::{collections::HashMap, sync::Arc, time::Duration}; use async_trait::async_trait; +use bevy_reflect::TypeUuid; use futures::FutureExt; use tedge_api::{ address::ReplySenderFor, @@ -10,7 +11,6 @@ use tedge_api::{ PluginError, }; use tokio::sync::RwLock; -use type_uuid::TypeUuid; #[derive(Debug, TypeUuid)] #[uuid = "94916be9-17ba-4bca-a3a0-408d33136fed"] diff --git a/crates/core/tedge_api/examples/universal_log.rs b/crates/core/tedge_api/examples/universal_log.rs index 064ffa22..0a1c6793 100644 --- a/crates/core/tedge_api/examples/universal_log.rs +++ b/crates/core/tedge_api/examples/universal_log.rs @@ -1,6 +1,7 @@ use std::{collections::HashMap, sync::Arc, time::Duration}; use async_trait::async_trait; +use bevy_reflect::TypeUuid; use futures::FutureExt; use tedge_api::{ address::ReplySenderFor, @@ -10,16 +11,15 @@ use tedge_api::{ PluginError, }; use tokio::sync::RwLock; -use type_uuid::TypeUuid; /// A message that represents a heartbeat that gets sent to plugins #[derive(Debug, TypeUuid)] -#[uuid = "1f807f7b-888f-4881-a1b5-16380e32f8c2"] +#[uuid = "1f807f7b-888f-4881-a1b5-16380e32f8c2"] struct Heartbeat; impl Message for Heartbeat {} #[derive(Debug, TypeUuid)] -#[uuid = "346e233f-c24a-47e0-a15b-3ec0d1e19019"] +#[uuid = "346e233f-c24a-47e0-a15b-3ec0d1e19019"] struct RandomData; impl Message for RandomData {} diff --git a/crates/core/tedge_api/src/address.rs b/crates/core/tedge_api/src/address.rs index 4249ecfc..a183b11c 100644 --- a/crates/core/tedge_api/src/address.rs +++ b/crates/core/tedge_api/src/address.rs @@ -359,8 +359,8 @@ pub trait Contains<M: Message> {} /// ## Example /// /// ```rust +/// # use bevy_reflect::TypeUuid; /// # use tedge_api::{Message, make_receiver_bundle}; -/// # use type_uuid::TypeUuid; /// /// #[derive(Debug, TypeUuid)] /// #[uuid = "b4e62630-0404-4d39-b435-95d777029887"] @@ -404,9 +404,9 @@ macro_rules! make_receiver_bundle { mod tests { use std::sync::Arc; + use bevy_reflect::TypeUuid; use static_assertions::{assert_impl_all, assert_not_impl_any}; use tokio::sync::RwLock; - use type_uuid::TypeUuid; use crate::{ address::{InnerMessageSender, ReplyReceiverFor, ReplySenderFor}, diff --git a/crates/core/tedge_api/src/message.rs b/crates/core/tedge_api/src/message.rs index 1e63a368..dbde7feb 100644 --- a/crates/core/tedge_api/src/message.rs +++ b/crates/core/tedge_api/src/message.rs @@ -1,6 +1,6 @@ use downcast_rs::{impl_downcast, DowncastSync}; +use bevy_reflect::{TypeUuid, TypeUuidDynamic}; use serde::Serialize; -use type_uuid::{TypeUuid, TypeUuidDynamic}; use crate::address::AnyMessageBox; @@ -81,7 +81,7 @@ pub struct MessageType { } #[derive(Clone, PartialEq, Debug)] -struct Uuid([u8; 16]); +struct Uuid(bevy_reflect::Uuid); #[derive(Debug, Clone, Serialize)] enum MessageKind { @@ -113,10 +113,10 @@ impl MessageType { /// Get the [`MessageType`] for a `M`:[`Message`] #[must_use] pub fn for_message<M: Message + TypeUuid>() -> Self { - let id = M::UUID; + let id = M::TYPE_UUID; MessageType { name: std::any::type_name::<M>(), - kind: if id == AnyMessage::UUID { + kind: if id == AnyMessage::TYPE_UUID { MessageKind::Wildcard } else { MessageKind::Typed(Uuid(id)) @@ -125,10 +125,10 @@ impl MessageType { } pub(crate) fn from_message(msg: &dyn Message) -> Self { - let id = msg.uuid(); + let id = msg.type_uuid(); MessageType { - name: msg.type_name(), - kind: if id == AnyMessage::UUID { + name: TypeUuidDynamic::type_name(msg), + kind: if id == AnyMessage::TYPE_UUID { MessageKind::Wildcard } else { MessageKind::Typed(Uuid(id)) @@ -154,7 +154,7 @@ crate::make_receiver_bundle!(pub struct CoreMessages(StopCore)); #[cfg(test)] mod tests { - use type_uuid::TypeUuid; + use bevy_reflect::TypeUuid; use crate::Message; diff --git a/crates/core/tedge_api/src/plugin.rs b/crates/core/tedge_api/src/plugin.rs index 718dbf67..2129d4bf 100644 --- a/crates/core/tedge_api/src/plugin.rs +++ b/crates/core/tedge_api/src/plugin.rs @@ -4,9 +4,9 @@ //! - Its purpose is to simply instantiate your plugins as needed with custom logic if required //! 2. Create your plugin struct that implements `Plugin` +use bevy_reflect::TypeUuid; use futures::future::BoxFuture; use std::any::Any; -use type_uuid::TypeUuid; use downcast_rs::{impl_downcast, DowncastSync}; @@ -96,8 +96,8 @@ pub trait PluginBuilder<PD: PluginDirectory>: Sync + Send + 'static { /// # Example /// /// ```no_run + /// # use bevy_reflect::TypeUuid; /// # use tedge_api::{Plugin, plugin::BuiltPlugin, PluginError, PluginExt, PluginDirectory, PluginBuilder, PluginConfiguration}; - /// # use type_uuid::TypeUuid; /// /// #[derive(Debug, TypeUuid)] /// #[uuid = "46f5d318-4158-4726-83dd-9b310cae3328"] @@ -214,13 +214,13 @@ pub trait PluginBuilder<PD: PluginDirectory>: Sync + Send + 'static { /// # Example /// /// ```no_run + /// # use bevy_reflect::TypeUuid; /// # use tedge_api::plugin::BuiltPlugin; /// # use tedge_api::PluginConfiguration; /// # use tedge_api::Plugin; /// # use tedge_api::PluginBuilder; /// # use tedge_api::PluginDirectory; /// # use tedge_api::PluginExt; - /// # use type_uuid::TypeUuid; /// /// #[derive(Debug, TypeUuid)] /// #[uuid = "39046e3e-05ad-4b16-bbf1-8c2d2da5b668"] @@ -384,11 +384,11 @@ impl HandleTypes { /// /// ```rust /// # use async_trait::async_trait; + /// # use bevy_reflect::TypeUuid; /// # use tedge_api::plugin::{Handle, HandleTypes}; /// # use tedge_api::address::ReplySenderFor; /// # use tedge_api::PluginError; /// # use tedge_api::PluginExt; - /// # use type_uuid::TypeUuid; /// /// #[derive(Debug, TypeUuid)] /// #[uuid = "1276aa9c-5e04-4ab3-a987-61d89765ab33"] @@ -677,9 +677,9 @@ impl_msg_bundle_tuple!(M10 M9 M8 M7 M6 M5 M4 M3 M2 M1); mod tests { use crate::{message::DynMessage, Message}; + use bevy_reflect::TypeUuid; use super::{Plugin, PluginBuilder}; use static_assertions::assert_obj_safe; - use type_uuid::TypeUuid; // Object Safety assert_obj_safe!(PluginBuilder<()>); |