Appease Clippy

This commit is contained in:
David Palm committed 2021-03-25 12:07:54 +01:00
1 parent 8f5f2102f9
commit 1d2183df24
6 files changed
+18 -22

No files matched your search

+4 -6
View File
@@ -79,12 +79,10 @@ impl Chain {
if &*self.label.0 == label { if &*self.label.0 == label {
self.label.1 += 1; self.label.1 += 1;
} else { } else if count > self.label.1 {
if count > self.label.1 {
self.rename(label.into(), count); self.rename(label.into(), count);
} }
} }
}
fn decrement_label_count(&mut self, label: &str) { fn decrement_label_count(&mut self, label: &str) {
match self.labels.get_mut(label) { match self.labels.get_mut(label) {
@@ -172,7 +170,7 @@ impl Chain {
self.block_times.reset(); self.block_times.reset();
self.timestamp = timestamp; self.timestamp = timestamp;
self.serializer.push(feed::BestBlock(self.best.height, timestamp.unwrap_or_else(|| now), None)); self.serializer.push(feed::BestBlock(self.best.height, timestamp.unwrap_or(now), None));
self.serializer.push(feed::BestFinalized(finalized.height, finalized.hash)); self.serializer.push(feed::BestFinalized(finalized.height, finalized.hash));
} }
} }
@@ -259,7 +257,7 @@ impl Handler<AddNode> for Chain {
let nid = self.nodes.add(Node::new(node)); let nid = self.nodes.add(Node::new(node));
let chain = ctx.address(); let chain = ctx.address();
if let Err(_) = rec.do_send(Initialize { nid, conn_id, chain }) { if rec.do_send(Initialize { nid, conn_id, chain }).is_err() {
self.nodes.remove(nid); self.nodes.remove(nid);
} else if let Some(node) = self.nodes.get(nid) { } else if let Some(node) = self.nodes.get(nid) {
self.serializer.push(feed::AddedNode(nid, node)); self.serializer.push(feed::AddedNode(nid, node));
@@ -456,7 +454,7 @@ impl Handler<Subscribe> for Chain {
self.serializer.push(feed::TimeSync(now())); self.serializer.push(feed::TimeSync(now()));
self.serializer.push(feed::BestBlock( self.serializer.push(feed::BestBlock(
self.best.height, self.best.height,
self.timestamp.unwrap_or_else(|| 0), self.timestamp.unwrap_or(0),
self.average_block_time, self.average_block_time,
)); ));
self.serializer.push(feed::BestFinalized(self.finalized.height, self.finalized.hash)); self.serializer.push(feed::BestFinalized(self.finalized.height, self.finalized.hash));
+1 -1
View File
@@ -46,7 +46,7 @@ impl FeedMessageSerializer {
} }
pub fn finalize(&mut self) -> Option<Serialized> { pub fn finalize(&mut self) -> Option<Serialized> {
if self.buffer.len() == 0 { if self.buffer.is_empty() {
return None; return None;
} }
+9 -8
View File
@@ -20,10 +20,10 @@ use node::connector::NodeConnector;
use types::NodeId; use types::NodeId;
use util::{Locator, LocatorFactory}; use util::{Locator, LocatorFactory};
const VERSION: &'static str = env!("CARGO_PKG_VERSION"); const VERSION: &str = env!("CARGO_PKG_VERSION");
const AUTHORS: &'static str = env!("CARGO_PKG_AUTHORS"); const AUTHORS: &str = env!("CARGO_PKG_AUTHORS");
const NAME: &'static str = "Substrate Telemetry Backend"; const NAME: &str = "Substrate Telemetry Backend";
const ABOUT: &'static str = "This is the Telemetry Backend that injects and provide the data sent by Substrate/Polkadot nodes"; const ABOUT: &str = "This is the Telemetry Backend that injects and provide the data sent by Substrate/Polkadot nodes";
#[derive(Clap)] #[derive(Clap)]
#[clap(name = NAME, version = VERSION, author = AUTHORS, about = ABOUT)] #[clap(name = NAME, version = VERSION, author = AUTHORS, about = ABOUT)]
@@ -54,9 +54,9 @@ enum LogLevel {
Trace, Trace,
} }
impl Into<log::LevelFilter> for &LogLevel { impl From<&LogLevel> for log::LevelFilter {
fn into(self) -> log::LevelFilter { fn from(log_level: &LogLevel) -> Self {
match self { match log_level {
LogLevel::Error => log::LevelFilter::Error, LogLevel::Error => log::LevelFilter::Error,
LogLevel::Warn => log::LevelFilter::Warn, LogLevel::Warn => log::LevelFilter::Warn,
LogLevel::Info => log::LevelFilter::Info, LogLevel::Info => log::LevelFilter::Info,
@@ -65,6 +65,7 @@ impl Into<log::LevelFilter> for &LogLevel {
} }
} }
} }
/// Entry point for connecting nodes /// Entry point for connecting nodes
#[get("/submit/")] #[get("/submit/")]
async fn node_route( async fn node_route(
@@ -74,7 +75,7 @@ async fn node_route(
locator: web::Data<Addr<Locator>>, locator: web::Data<Addr<Locator>>,
) -> Result<HttpResponse, Error> { ) -> Result<HttpResponse, Error> {
let ip = req.connection_info().realip_remote_addr().and_then(|mut addr| { let ip = req.connection_info().realip_remote_addr().and_then(|mut addr| {
if let Some(port_idx) = addr.find(":") { if let Some(port_idx) = addr.find(':') {
addr = &addr[..port_idx]; addr = &addr[..port_idx];
} }
addr.parse::<Ipv4Addr>().ok() addr.parse::<Ipv4Addr>().ok()
+1 -4
View File
@@ -89,10 +89,7 @@ impl Node {
} }
pub fn location(&self) -> Option<&NodeLocation> { pub fn location(&self) -> Option<&NodeLocation> {
match self.location { self.location.as_deref()
Some(ref location) => Some(&**location),
None => None
}
} }
pub fn update_location(&mut self, location: Arc<NodeLocation>) { pub fn update_location(&mut self, location: Arc<NodeLocation>) {
+1 -1
View File
@@ -118,7 +118,7 @@ impl NodeConnector {
_ => (), _ => (),
} }
self.aggregator.do_send(AddNode { rec, conn_id, node }); self.aggregator.do_send(AddNode { node, conn_id, rec });
} else { } else {
if backlog.len() >= 10 { if backlog.len() >= 10 {
backlog.remove(0); backlog.remove(0);
+2 -2
View File
@@ -26,7 +26,7 @@ impl LocatorFactory {
// Default entry for localhost // Default entry for localhost
cache.insert( cache.insert(
Ipv4Addr::new(127, 0, 0, 1), Ipv4Addr::new(127, 0, 0, 1),
Some(Arc::new(NodeLocation { latitude: 52.5166667, longitude: 13.4, city: "Berlin".into() })), Some(Arc::new(NodeLocation { latitude: 52.516_6667, longitude: 13.4, city: "Berlin".into() })),
); );
LocatorFactory { LocatorFactory {
@@ -64,7 +64,7 @@ impl IPApiLocate {
fn into_node_location(self) -> Option<NodeLocation> { fn into_node_location(self) -> Option<NodeLocation> {
let IPApiLocate { city, loc } = self; let IPApiLocate { city, loc } = self;
let mut loc = loc.split(",").map(|n| n.parse()); let mut loc = loc.split(',').map(|n| n.parse());
let latitude = loc.next()?.ok()?; let latitude = loc.next()?.ok()?;
let longitude = loc.next()?.ok()?; let longitude = loc.next()?.ok()?;