diff options
author | Alex Auvolat <alex@adnab.me> | 2021-10-14 11:35:05 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2021-10-14 11:35:05 +0200 |
commit | 01a2737bd8537da41a3babdd2b0949795492a59e (patch) | |
tree | 095b9151b7fbfae87412643bb4e6ec9b76ac32c3 /src/netapp.rs | |
parent | baa714538d14cb3eb7d29468962946059b4318fd (diff) | |
download | netapp-01a2737bd8537da41a3babdd2b0949795492a59e.tar.gz netapp-01a2737bd8537da41a3babdd2b0949795492a59e.zip |
Document
Diffstat (limited to 'src/netapp.rs')
-rw-r--r-- | src/netapp.rs | 17 |
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 } |