Unverified Commit 25787285 authored by David's avatar David Committed by GitHub
Browse files

Apease Clippy and some renames (#268)



* Apease Clippy and some renames

* Last clippy warning

* fmt

Co-authored-by: Niklas Adolfsson's avatarNiklas Adolfsson <niklasadolfsson1@gmail.com>
parent 495e0bb3
......@@ -35,7 +35,7 @@ impl HttpTransportClient {
#[cfg(feature = "tokio02")]
let connector = HttpsConnector::new();
let client = Client::builder().build::<_, hyper::Body>(connector);
Ok(HttpTransportClient { client, target, max_request_body_size })
Ok(HttpTransportClient { target, client, max_request_body_size })
} else {
Err(Error::Url("URL scheme not supported, expects 'http' or 'https'".into()))
}
......
......@@ -49,22 +49,22 @@ pub enum OriginProtocol {
pub struct Origin {
protocol: OriginProtocol,
host: Host,
as_string: String,
host_with_proto: String,
matcher: Matcher,
}
impl<T: AsRef<str>> From<T> for Origin {
fn from(string: T) -> Self {
Origin::parse(string.as_ref())
fn from(origin: T) -> Self {
Origin::parse(origin.as_ref())
}
}
impl Origin {
fn with_host(protocol: OriginProtocol, host: Host) -> Self {
let string = Self::to_string(&protocol, &host);
let matcher = Matcher::new(&string);
let host_with_proto = Self::host_with_proto(&protocol, &host);
let matcher = Matcher::new(&host_with_proto);
Origin { protocol, host, as_string: string, matcher }
Origin { protocol, host, host_with_proto, matcher }
}
/// Creates new origin given protocol, hostname and port parts.
......@@ -75,10 +75,10 @@ impl Origin {
/// Attempts to parse given string as a `Origin`.
/// NOTE: This method always succeeds and falls back to sensible defaults.
pub fn parse(data: &str) -> Self {
let mut it = data.split("://");
let proto = it.next().expect("split always returns non-empty iterator.");
let hostname = it.next();
pub fn parse(origin: &str) -> Self {
let mut parts = origin.split("://");
let proto = parts.next().expect("split always returns non-empty iterator.");
let hostname = parts.next();
let (proto, hostname) = match hostname {
None => (None, proto),
......@@ -98,7 +98,7 @@ impl Origin {
Origin::with_host(protocol, hostname)
}
fn to_string(protocol: &OriginProtocol, host: &Host) -> String {
fn host_with_proto(protocol: &OriginProtocol, host: &Host) -> String {
format!(
"{}://{}",
match *protocol {
......@@ -120,7 +120,7 @@ impl Pattern for Origin {
impl ops::Deref for Origin {
type Target = str;
fn deref(&self) -> &Self::Target {
&self.as_string
&self.host_with_proto
}
}
......
......@@ -61,7 +61,7 @@ impl From<u16> for Port {
pub struct Host {
hostname: String,
port: Port,
as_string: String,
host_with_port: String,
matcher: Matcher,
}
......@@ -76,10 +76,10 @@ impl Host {
pub fn new<T: Into<Port>>(hostname: &str, port: T) -> Self {
let port = port.into();
let hostname = Self::pre_process(hostname);
let string = Self::to_string(&hostname, &port);
let matcher = Matcher::new(&string);
let host_with_port = Self::from_str(&hostname, &port);
let matcher = Matcher::new(&host_with_port);
Host { hostname, port, as_string: string, matcher }
Host { hostname, port, host_with_port, matcher }
}
/// Attempts to parse given string as a `Host`.
......@@ -112,7 +112,7 @@ impl Host {
it.next().expect(SPLIT_PROOF).to_lowercase()
}
fn to_string(hostname: &str, port: &Port) -> String {
fn from_str(hostname: &str, port: &Port) -> String {
format!(
"{}{}",
hostname,
......@@ -135,7 +135,7 @@ impl std::ops::Deref for Host {
type Target = str;
fn deref(&self) -> &Self::Target {
&self.as_string
&self.host_with_port
}
}
......
......@@ -126,8 +126,8 @@ impl Output {
/// Creates new output given `Result`, `Id` and `Version`.
pub fn from(result: Result<JsonValue, Error>, id: Id, jsonrpc: Version) -> Self {
match result {
Ok(result) => Output::Success(Success { id, jsonrpc, result }),
Err(error) => Output::Failure(Failure { id, jsonrpc, error }),
Ok(result) => Output::Success(Success { jsonrpc, result, id }),
Err(error) => Output::Failure(Failure { jsonrpc, error, id }),
}
}
......
......@@ -155,6 +155,7 @@ impl BatchState {
}
/// Extracts the next request from the batch. Returns `None` if the batch is empty.
#[allow(clippy::should_implement_trait)]
pub fn next(&mut self) -> Option<BatchInc> {
if self.to_yield.is_empty() {
return None;
......
......@@ -24,6 +24,7 @@
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
use crate::error::Error;
use crate::jsonrpc;
use alloc::string::String;
......@@ -53,12 +54,12 @@ impl<'a> Params<'a> {
/// Returns a parameter of the request by name and decodes it.
///
/// Returns an error if the parameter doesn't exist or is of the wrong type.
pub fn get<'k, T>(self, param: impl Into<ParamKey<'k>>) -> Result<T, ()>
pub fn get<'k, T>(self, param: impl Into<ParamKey<'k>>) -> Result<T, Error>
where
T: serde::de::DeserializeOwned,
{
let val = self.get_raw(param).ok_or(())?;
serde_json::from_value(val.clone()).map_err(|_| ())
let val = self.get_raw(param).ok_or_else(|| Error::Custom("No such param".into()))?;
serde_json::from_value(val.clone()).map_err(Error::ParseError)
}
/// Returns a parameter of the request by name.
......
......@@ -53,11 +53,12 @@ mod module;
pub use module::{RpcContextModule, RpcModule};
type SubscriptionId = u64;
type Subscribers = Arc<Mutex<FxHashMap<(ConnectionId, SubscriptionId), mpsc::UnboundedSender<String>>>>;
#[derive(Clone)]
pub struct SubscriptionSink {
method: &'static str,
subscribers: Arc<Mutex<FxHashMap<(ConnectionId, SubscriptionId), mpsc::UnboundedSender<String>>>>,
subscribers: Subscribers,
}
impl SubscriptionSink {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment