Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add equality/ordering/hash trait bounds to RPC URL types #921

Merged
merged 4 commits into from
Jun 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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