aboutsummaryrefslogtreecommitdiff
path: root/src/netapp.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/netapp.rs')
-rw-r--r--src/netapp.rs17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/netapp.rs b/src/netapp.rs
index bffa0e1..7fe1e71 100644
--- a/src/netapp.rs
+++ b/src/netapp.rs
@@ -125,21 +125,30 @@ impl NetApp {
.store(Some(Arc::new(Box::new(handler))));
}
- pub fn endpoint<M, H>(self: &Arc<Self>, name: String) -> Arc<Endpoint<M, H>>
+ /// Create a new endpoint with path `path`,
+ /// that handles messages of type `M`.
+ /// `H` is the type of the object that should handle requests
+ /// to this endpoint on the local node. If you don't want
+ /// to handle request on the local node (e.g. if this node
+ /// is only a client in the network), define the type `H`
+ /// to be `()`.
+ /// This function will panic if the endpoint has already been
+ /// created.
+ pub fn endpoint<M, H>(self: &Arc<Self>, path: String) -> Arc<Endpoint<M, H>>
where
M: Message + 'static,
H: EndpointHandler<M> + 'static,
{
- let endpoint = Arc::new(Endpoint::<M, H>::new(self.clone(), name.clone()));
+ let endpoint = Arc::new(Endpoint::<M, H>::new(self.clone(), path.clone()));
let endpoint_arc = EndpointArc(endpoint.clone());
if self
.endpoints
.write()
.unwrap()
- .insert(name.clone(), Box::new(endpoint_arc))
+ .insert(path.clone(), Box::new(endpoint_arc))
.is_some()
{
- panic!("Redefining endpoint: {}", name);
+ panic!("Redefining endpoint: {}", path);
};
endpoint
}