pub struct IPCBuilder { /* private fields */ }
Expand description
A builder for the IPC server or client.
use typemap_rev::TypeMapKey;
use rmp_ipc::IPCBuilder;
struct CustomKey;
impl TypeMapKey for CustomKey {
type Value = String;
}
IPCBuilder::new()
.address("127.0.0.1:2020")
// register callback
.on("ping", |_ctx, _event| Box::pin(async move {
println!("Received ping event.");
Ok(())
}))
// register a namespace
.namespace("namespace")
.on("namespace-event", |_ctx, _event| Box::pin(async move {
println!("Namespace event.");
Ok(())
}))
.build()
// add context shared data
.insert::<CustomKey>("Hello World".to_string())
// can also be build_client which would return an emitter for events
.build_server().await.unwrap();
Implementations§
Source§impl IPCBuilder
impl IPCBuilder
pub fn new() -> Self
Sourcepub fn insert<K: TypeMapKey>(self, value: K::Value) -> Self
pub fn insert<K: TypeMapKey>(self, value: K::Value) -> Self
Adds globally shared data
Sourcepub fn namespace<S: ToString>(self, name: S) -> NamespaceBuilder
pub fn namespace<S: ToString>(self, name: S) -> NamespaceBuilder
Adds a namespace
Sourcepub fn add_namespace(self, namespace: Namespace) -> Self
pub fn add_namespace(self, namespace: Namespace) -> Self
Adds a namespace to the ipc server
Sourcepub async fn build_server(self) -> Result<()>
pub async fn build_server(self) -> Result<()>
Builds an ipc server
Sourcepub async fn build_client(self) -> Result<Context>
pub async fn build_client(self) -> Result<Context>
Builds an ipc client
Sourcepub async fn build_pooled_client(
self,
pool_size: usize,
) -> Result<PooledContext>
pub async fn build_pooled_client( self, pool_size: usize, ) -> Result<PooledContext>
Builds a pooled IPC client
This causes the builder to actually create pool_size
clients and
return a crate::context::PooledContext that allows one to crate::context::PooledContext::acquire a single context
to emit events.
Auto Trait Implementations§
impl Freeze for IPCBuilder
impl !RefUnwindSafe for IPCBuilder
impl Send for IPCBuilder
impl Sync for IPCBuilder
impl Unpin for IPCBuilder
impl !UnwindSafe for IPCBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more