From 01a2737bd8537da41a3babdd2b0949795492a59e Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Thu, 14 Oct 2021 11:35:05 +0200 Subject: Document --- src/netapp.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/netapp.rs') 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(self: &Arc, name: String) -> Arc> + /// 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(self: &Arc, path: String) -> Arc> where M: Message + 'static, H: EndpointHandler + 'static, { - let endpoint = Arc::new(Endpoint::::new(self.clone(), name.clone())); + let endpoint = Arc::new(Endpoint::::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 } -- cgit v1.2.3