|
|
@ -12,19 +12,18 @@ use crate::namespaces::namespace::Namespace;
|
|
|
|
#[cfg(feature = "serialize")]
|
|
|
|
#[cfg(feature = "serialize")]
|
|
|
|
use crate::payload::DynamicSerializer;
|
|
|
|
use crate::payload::DynamicSerializer;
|
|
|
|
use crate::protocol::AsyncStreamProtocolListener;
|
|
|
|
use crate::protocol::AsyncStreamProtocolListener;
|
|
|
|
use std::any::{Any, TypeId};
|
|
|
|
|
|
|
|
use std::collections::HashMap;
|
|
|
|
use std::collections::HashMap;
|
|
|
|
use std::future::Future;
|
|
|
|
use std::future::Future;
|
|
|
|
use std::pin::Pin;
|
|
|
|
use std::pin::Pin;
|
|
|
|
use std::sync::Arc;
|
|
|
|
use std::sync::Arc;
|
|
|
|
use std::time::Duration;
|
|
|
|
use std::time::Duration;
|
|
|
|
use tokio::sync::RwLock;
|
|
|
|
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.
|
|
|
|
/// A builder for the IPC server or client.
|
|
|
|
/// ```no_run
|
|
|
|
/// ```no_run
|
|
|
|
/// use std::net::ToSocketAddrs;
|
|
|
|
/// use std::net::ToSocketAddrs;
|
|
|
|
/// use typemap_rev::TypeMapKey;
|
|
|
|
/// use trait_bound_typemap::TypeMapKey;
|
|
|
|
/// use bromine::IPCBuilder;
|
|
|
|
/// use bromine::IPCBuilder;
|
|
|
|
/// use tokio::net::TcpListener;
|
|
|
|
/// use tokio::net::TcpListener;
|
|
|
|
/// use bromine::prelude::Response;
|
|
|
|
/// use bromine::prelude::Response;
|
|
|
@ -61,7 +60,7 @@ pub struct IPCBuilder<L: AsyncStreamProtocolListener> {
|
|
|
|
handler: EventHandler,
|
|
|
|
handler: EventHandler,
|
|
|
|
address: Option<L::AddressType>,
|
|
|
|
address: Option<L::AddressType>,
|
|
|
|
namespaces: HashMap<String, Namespace>,
|
|
|
|
namespaces: HashMap<String, Namespace>,
|
|
|
|
data: TypeMap,
|
|
|
|
data: SendSyncTypeMap,
|
|
|
|
timeout: Duration,
|
|
|
|
timeout: Duration,
|
|
|
|
#[cfg(feature = "serialize")]
|
|
|
|
#[cfg(feature = "serialize")]
|
|
|
|
default_serializer: DynamicSerializer,
|
|
|
|
default_serializer: DynamicSerializer,
|
|
|
@ -86,7 +85,7 @@ where
|
|
|
|
handler,
|
|
|
|
handler,
|
|
|
|
address: None,
|
|
|
|
address: None,
|
|
|
|
namespaces: HashMap::new(),
|
|
|
|
namespaces: HashMap::new(),
|
|
|
|
data: TypeMap::new(),
|
|
|
|
data: SendSyncTypeMap::new(),
|
|
|
|
timeout: Duration::from_secs(60),
|
|
|
|
timeout: Duration::from_secs(60),
|
|
|
|
#[cfg(feature = "serialize")]
|
|
|
|
#[cfg(feature = "serialize")]
|
|
|
|
default_serializer: DynamicSerializer::first_available(),
|
|
|
|
default_serializer: DynamicSerializer::first_available(),
|
|
|
@ -94,14 +93,17 @@ where
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Adds globally shared data
|
|
|
|
/// Adds globally shared data
|
|
|
|
pub fn insert<K: TypeMapKey>(mut self, value: K::Value) -> Self {
|
|
|
|
pub fn insert<K: TypeMapKey>(mut self, value: K::Value) -> Self
|
|
|
|
|
|
|
|
where
|
|
|
|
|
|
|
|
<K as TypeMapKey>::Value: Send + Sync,
|
|
|
|
|
|
|
|
{
|
|
|
|
self.data.insert::<K>(value);
|
|
|
|
self.data.insert::<K>(value);
|
|
|
|
|
|
|
|
|
|
|
|
self
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Adds all the data from the other given type map
|
|
|
|
/// Adds all the data from the other given type map
|
|
|
|
pub fn insert_all<I: IntoIterator<Item = (TypeId, Box<dyn Any + Send + Sync>)>>(
|
|
|
|
pub fn insert_all<I: IntoIterator<Item = TypeMapEntry<K>>, K: KeyCanExtend<SendSyncTypeMap>>(
|
|
|
|
mut self,
|
|
|
|
mut self,
|
|
|
|
value: I,
|
|
|
|
value: I,
|
|
|
|
) -> Self {
|
|
|
|
) -> Self {
|
|
|
|