diff --git a/Cargo.lock b/Cargo.lock index 1478dd0a..49e57c63 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -93,7 +93,7 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bromine" -version = "0.18.2" +version = "0.19.0" dependencies = [ "async-trait", "bincode", @@ -111,7 +111,7 @@ dependencies = [ "thiserror", "tokio", "tracing", - "typemap_rev", + "trait-bound-typemap", ] [[package]] @@ -538,6 +538,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "multi-trait-object" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a54c9ed2b86c7927b63e7d51f8d7ed4e1f8513c8672828ca1a850ff9d32ab1c" + [[package]] name = "nb" version = "0.1.3" @@ -1035,9 +1041,13 @@ dependencies = [ ] [[package]] -name = "typemap_rev" -version = "0.1.5" -source = "git+https://github.com/Trivernis/typemap_rev?rev=750c67bffe8024d2a47725daa473f068ad653fc4#750c67bffe8024d2a47725daa473f068ad653fc4" +name = "trait-bound-typemap" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3631df5ba73c0e41b1aa337df3bcca7f15219f042f8fec1100857bc1eb60c767" +dependencies = [ + "multi-trait-object", +] [[package]] name = "unicode-width" diff --git a/Cargo.toml b/Cargo.toml index a0a983a7..a197f693 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bromine" -version = "0.18.3" +version = "0.19.0" authors = ["trivernis "] edition = "2018" readme = "README.md" @@ -27,15 +27,11 @@ byteorder = "1.4.3" async-trait = "0.1.52" num_enum = "0.5.7" futures-core = "0.3.21" +trait-bound-typemap = "0.3.3" rmp-serde = { version = "1.0.0", optional = true } bincode = { version = "1.3.3", optional = true } serde_json = { version = "1.0.79", optional = true } -[dependencies.typemap_rev] -version = "0.1.5" -git = "https://github.com/Trivernis/typemap_rev" -rev = "750c67bffe8024d2a47725daa473f068ad653fc4" - [dependencies.serde] optional = true version = "1.0.136" diff --git a/src/ipc/builder.rs b/src/ipc/builder.rs index 08d3ab9a..4183f05e 100644 --- a/src/ipc/builder.rs +++ b/src/ipc/builder.rs @@ -12,19 +12,18 @@ use crate::namespaces::namespace::Namespace; #[cfg(feature = "serialize")] use crate::payload::DynamicSerializer; use crate::protocol::AsyncStreamProtocolListener; -use std::any::{Any, TypeId}; use std::collections::HashMap; use std::future::Future; use std::pin::Pin; use std::sync::Arc; use std::time::Duration; use tokio::sync::RwLock; -use typemap_rev::{TypeMap, TypeMapKey}; +use trait_bound_typemap::{KeyCanExtend, SendSyncTypeMap, TypeMap, TypeMapEntry, TypeMapKey}; /// A builder for the IPC server or client. /// ```no_run /// use std::net::ToSocketAddrs; -/// use typemap_rev::TypeMapKey; +/// use trait_bound_typemap::TypeMapKey; /// use bromine::IPCBuilder; /// use tokio::net::TcpListener; /// use bromine::prelude::Response; @@ -61,7 +60,7 @@ pub struct IPCBuilder { handler: EventHandler, address: Option, namespaces: HashMap, - data: TypeMap, + data: SendSyncTypeMap, timeout: Duration, #[cfg(feature = "serialize")] default_serializer: DynamicSerializer, @@ -86,7 +85,7 @@ where handler, address: None, namespaces: HashMap::new(), - data: TypeMap::new(), + data: SendSyncTypeMap::new(), timeout: Duration::from_secs(60), #[cfg(feature = "serialize")] default_serializer: DynamicSerializer::first_available(), @@ -94,14 +93,17 @@ where } /// Adds globally shared data - pub fn insert(mut self, value: K::Value) -> Self { + pub fn insert(mut self, value: K::Value) -> Self + where + ::Value: Send + Sync, + { self.data.insert::(value); self } /// Adds all the data from the other given type map - pub fn insert_all)>>( + pub fn insert_all>, K: KeyCanExtend>( mut self, value: I, ) -> Self { diff --git a/src/ipc/client.rs b/src/ipc/client.rs index 157d16f8..ae7f8600 100644 --- a/src/ipc/client.rs +++ b/src/ipc/client.rs @@ -10,7 +10,7 @@ use std::sync::Arc; use std::time::Duration; use tokio::sync::oneshot; use tokio::sync::RwLock; -use typemap_rev::TypeMap; +use trait_bound_typemap::SendSyncTypeMap; #[cfg(feature = "serialize")] use crate::payload::DynamicSerializer; @@ -22,7 +22,7 @@ use crate::payload::DynamicSerializer; pub struct IPCClient { pub(crate) handler: EventHandler, pub(crate) namespaces: HashMap, - pub(crate) data: Arc>, + pub(crate) data: Arc>, pub(crate) reply_listeners: ReplyListeners, pub(crate) timeout: Duration, diff --git a/src/ipc/context.rs b/src/ipc/context.rs index 1f0e081e..a44ead8a 100644 --- a/src/ipc/context.rs +++ b/src/ipc/context.rs @@ -7,7 +7,7 @@ use std::sync::Arc; use tokio::sync::mpsc::Receiver; use tokio::sync::{mpsc, oneshot, Mutex, RwLock}; use tokio::time::Duration; -use typemap_rev::TypeMap; +use trait_bound_typemap::SendSyncTypeMap; use crate::error::{Error, Result}; use crate::event::{Event, EventType}; @@ -38,7 +38,7 @@ pub struct Context { emitter: StreamEmitter, /// Field to store additional context data - pub data: Arc>, + pub data: Arc>, stop_sender: Arc>>>, @@ -55,7 +55,7 @@ pub struct Context { impl Context { pub(crate) fn new( emitter: StreamEmitter, - data: Arc>, + data: Arc>, stop_sender: Option>, reply_listeners: ReplyListeners, reply_timeout: Duration, diff --git a/src/ipc/server.rs b/src/ipc/server.rs index a415b238..9a71a66c 100644 --- a/src/ipc/server.rs +++ b/src/ipc/server.rs @@ -13,7 +13,7 @@ use std::collections::HashMap; use std::sync::Arc; use std::time::Duration; use tokio::sync::RwLock; -use typemap_rev::TypeMap; +use trait_bound_typemap::SendSyncTypeMap; /// The IPC Server listening for connections. /// Use the [IPCBuilder](crate::builder::IPCBuilder) to create a server. @@ -21,7 +21,7 @@ use typemap_rev::TypeMap; pub struct IPCServer { pub(crate) handler: EventHandler, pub(crate) namespaces: HashMap, - pub(crate) data: TypeMap, + pub(crate) data: SendSyncTypeMap, pub(crate) timeout: Duration, #[cfg(feature = "serialize")] diff --git a/src/lib.rs b/src/lib.rs index 6ba5e22b..d15bc06e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -61,7 +61,7 @@ //! Server Example: //! ```no_run //! use std::net::ToSocketAddrs; -//! use typemap_rev::TypeMapKey; +//! use trait_bound_typemap::{TypeMapKey, TypeMap}; //! use bromine::IPCBuilder; //! use bromine::prelude::*; //! use tokio::net::TcpListener; diff --git a/tests/utils/call_counter.rs b/tests/utils/call_counter.rs index 5df1d067..a9d61dd9 100644 --- a/tests/utils/call_counter.rs +++ b/tests/utils/call_counter.rs @@ -4,7 +4,7 @@ use std::collections::HashMap; use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Arc; use tokio::sync::RwLock; -use typemap_rev::TypeMapKey; +use trait_bound_typemap::{TypeMap, TypeMapKey}; pub async fn get_counter_from_context(ctx: &Context) -> CallCounter { let data = ctx.data.read().await;