From 7b8478135010d51e778d2756ebe0eab2e8f02cf6 Mon Sep 17 00:00:00 2001 From: Thane Thomson Date: Sun, 27 Jun 2021 08:00:12 -0400 Subject: [PATCH] Add equality/ordering/hash trait bounds to RPC URL types (#921) --- .changelog/unreleased/improvements/919-rpc-url-bounds.md | 3 +++ rpc/src/client/transport/http.rs | 8 +++++++- rpc/src/client/transport/websocket.rs | 8 +++++++- rpc/src/rpc_url.rs | 4 ++-- 4 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 .changelog/unreleased/improvements/919-rpc-url-bounds.md diff --git a/.changelog/unreleased/improvements/919-rpc-url-bounds.md b/.changelog/unreleased/improvements/919-rpc-url-bounds.md new file mode 100644 index 000000000..d65cd0103 --- /dev/null +++ b/.changelog/unreleased/improvements/919-rpc-url-bounds.md @@ -0,0 +1,3 @@ +* `[tendermint-rpc]` Add `PartialEq`, `Eq`, `PartialOrd`, `Ord` and `Hash` trait + bounds to the RPC URL types + ([#919](https://github.com/informalsystems/tendermint-rs/issues/919)) diff --git a/rpc/src/client/transport/http.rs b/rpc/src/client/transport/http.rs index 29e4b9604..4513b3b0b 100644 --- a/rpc/src/client/transport/http.rs +++ b/rpc/src/client/transport/http.rs @@ -92,7 +92,7 @@ impl Client for HttpClient { /// A URL limited to use with HTTP clients. /// /// Facilitates useful type conversions and inferences. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct HttpClientUrl(Url); impl TryFrom for HttpClientUrl { @@ -143,6 +143,12 @@ impl TryFrom for HttpClientUrl { } } +impl From for Url { + fn from(url: HttpClientUrl) -> Self { + url.0 + } +} + impl TryFrom for hyper::Uri { type Error = Error; diff --git a/rpc/src/client/transport/websocket.rs b/rpc/src/client/transport/websocket.rs index 7e728ef35..dc0256358 100644 --- a/rpc/src/client/transport/websocket.rs +++ b/rpc/src/client/transport/websocket.rs @@ -172,7 +172,7 @@ impl SubscriptionClient for WebSocketClient { /// A URL limited to use with WebSocket clients. /// /// Facilitates useful type conversions and inferences. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct WebSocketClientUrl(Url); impl TryFrom for WebSocketClientUrl { @@ -223,6 +223,12 @@ impl TryFrom for WebSocketClientUrl { } } +impl From for Url { + fn from(url: WebSocketClientUrl) -> Self { + url.0 + } +} + mod sealed { use super::{ DriverCommand, SimpleRequestCommand, SubscribeCommand, UnsubscribeCommand, diff --git a/rpc/src/rpc_url.rs b/rpc/src/rpc_url.rs index e909ed41f..c0896df68 100644 --- a/rpc/src/rpc_url.rs +++ b/rpc/src/rpc_url.rs @@ -7,7 +7,7 @@ use std::fmt; use std::str::FromStr; /// The various schemes supported by Tendermint RPC clients. -#[derive(Debug, Clone, Copy, Eq, PartialEq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum Scheme { Http, Https, @@ -50,7 +50,7 @@ impl FromStr for Scheme { /// /// Re-implements relevant parts of [`url::Url`]'s interface with convenience /// mechanisms for transformation to/from other types. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct Url { inner: url::Url, scheme: Scheme,