Skip to content

Commit

Permalink
Add equality/ordering/hash trait bounds to RPC URL types (#921)
Browse files Browse the repository at this point in the history
  • Loading branch information
thanethomson authored Jun 27, 2021
1 parent c8b97aa commit 7b84781
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .changelog/unreleased/improvements/919-rpc-url-bounds.md
Original file line number Diff line number Diff line change
@@ -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))
8 changes: 7 additions & 1 deletion rpc/src/client/transport/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Url> for HttpClientUrl {
Expand Down Expand Up @@ -143,6 +143,12 @@ impl TryFrom<net::Address> for HttpClientUrl {
}
}

impl From<HttpClientUrl> for Url {
fn from(url: HttpClientUrl) -> Self {
url.0
}
}

impl TryFrom<HttpClientUrl> for hyper::Uri {
type Error = Error;

Expand Down
8 changes: 7 additions & 1 deletion rpc/src/client/transport/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Url> for WebSocketClientUrl {
Expand Down Expand Up @@ -223,6 +223,12 @@ impl TryFrom<net::Address> for WebSocketClientUrl {
}
}

impl From<WebSocketClientUrl> for Url {
fn from(url: WebSocketClientUrl) -> Self {
url.0
}
}

mod sealed {
use super::{
DriverCommand, SimpleRequestCommand, SubscribeCommand, UnsubscribeCommand,
Expand Down
4 changes: 2 additions & 2 deletions rpc/src/rpc_url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 7b84781

Please sign in to comment.