From 0cbe57a3178160fb9bbe5e34b3e6e67d474c4b98 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Wed, 8 Feb 2023 15:40:23 -0700 Subject: [PATCH] feat: type aliases for 2D/3D NetworkCoordinates This just adds a few type aliases for convenience, and slightly better ergonomics for the most common usage (2D or 3D). Signed-off-by: Stephen Waits --- src/lib.rs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b7f30df..54d98f7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -69,16 +69,19 @@ //! forwarded to us by someone else. And in this case, we aren't measuring the actual RTT. Instead, //! we're using the NCs to estimate RTT. //! +//! This example also uses the type alias [`NetworkCoordinate3D`] instead of its equivalent +//! [`NetworkCoordinate<3>`]. +//! //! ``` -//! use vivaldi_nc::NetworkCoordinate; +//! use vivaldi_nc::NetworkCoordinate3D; //! //! // create our local NC as a 3-dimensional Vivaldi coordinate -//! let mut my_nc = NetworkCoordinate::<3>::new(); +//! let mut my_nc = NetworkCoordinate3D::new(); //! //! // mock up a remote NC for the sake of this example (normally the node would actually receive //! // this from a remote node) //! let received_msg = "{\"position\":[1.5,0.5,2.0],\"height\":0.1,\"error\":1.0}"; -//! let remote_nc: NetworkCoordinate<3> = serde_json::from_str(received_msg).unwrap(); +//! let remote_nc: NetworkCoordinate3D = serde_json::from_str(received_msg).unwrap(); //! //! // estimate the RTT to this remote node without measuring it directly //! let rtt_estimated = my_nc.estimated_rtt(&remote_nc); @@ -94,3 +97,17 @@ mod vector; // publish our interface pub mod network_coordinate; pub use network_coordinate::NetworkCoordinate; + +// type aliases for convenience + +/// A 2D [`NetworkCoordinate`]. Includes a 2D Euclidean position and a height. +/// +/// This type alias is just for convenience. It's functionally equivalent to +/// `NetworkCoordinate<2>`. +pub type NetworkCoordinate2D = NetworkCoordinate<2>; + +/// A 3D [`NetworkCoordinate`]. Includes a 3D Euclidean position and a height. +/// +/// This type alias is just for convenience. It's functionally equivalent to +/// `NetworkCoordinate<3>`. +pub type NetworkCoordinate3D = NetworkCoordinate<3>;