Run cargo fmt on the whole code base (#9394)

* Run cargo fmt on the whole code base

* Second run

* Add CI check

* Fix compilation

* More unnecessary braces

* Handle weights

* Use --all

* Use correct attributes...

* Fix UI tests

* AHHHHHHHHH

* 🤦

* Docs

* Fix compilation

* 🤷

* Please stop

* 🤦 x 2

* More

* make rustfmt.toml consistent with polkadot

Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
Bastian Köcher
2021-07-21 16:32:32 +02:00
committed by GitHub
parent d451c38c1c
commit 7b56ab15b4
1010 changed files with 53339 additions and 51208 deletions
+8 -11
View File
@@ -19,22 +19,20 @@
use lazy_static::lazy_static;
use prometheus::{
Registry, Error as PrometheusError,
core::{ AtomicU64, GenericGauge, GenericCounter },
core::{AtomicU64, GenericCounter, GenericGauge},
Error as PrometheusError, Registry,
};
#[cfg(feature = "metered")]
use prometheus::{core::GenericCounterVec, Opts};
lazy_static! {
pub static ref TOKIO_THREADS_TOTAL: GenericCounter<AtomicU64> = GenericCounter::new(
"tokio_threads_total", "Total number of threads created"
).expect("Creating of statics doesn't fail. qed");
pub static ref TOKIO_THREADS_ALIVE: GenericGauge<AtomicU64> = GenericGauge::new(
"tokio_threads_alive", "Number of threads alive right now"
).expect("Creating of statics doesn't fail. qed");
pub static ref TOKIO_THREADS_TOTAL: GenericCounter<AtomicU64> =
GenericCounter::new("tokio_threads_total", "Total number of threads created")
.expect("Creating of statics doesn't fail. qed");
pub static ref TOKIO_THREADS_ALIVE: GenericGauge<AtomicU64> =
GenericGauge::new("tokio_threads_alive", "Number of threads alive right now")
.expect("Creating of statics doesn't fail. qed");
}
#[cfg(feature = "metered")]
@@ -46,7 +44,6 @@ lazy_static! {
}
/// Register the statics to report to registry
pub fn register_globals(registry: &Registry) -> Result<(), PrometheusError> {
registry.register(Box::new(TOKIO_THREADS_ALIVE.clone()))?;
+35 -53
View File
@@ -25,22 +25,26 @@ mod inner {
pub type TracingUnboundedReceiver<T> = UnboundedReceiver<T>;
/// Alias `mpsc::unbounded`
pub fn tracing_unbounded<T>(_key: &'static str) ->(TracingUnboundedSender<T>, TracingUnboundedReceiver<T>) {
pub fn tracing_unbounded<T>(
_key: &'static str,
) -> (TracingUnboundedSender<T>, TracingUnboundedReceiver<T>) {
mpsc::unbounded()
}
}
#[cfg(feature = "metered")]
mod inner {
//tracing implementation
use futures::channel::mpsc::{self,
UnboundedReceiver, UnboundedSender,
TryRecvError, TrySendError, SendError
};
use futures::{sink::Sink, task::{Poll, Context}, stream::{Stream, FusedStream}};
use std::pin::Pin;
// tracing implementation
use crate::metrics::UNBOUNDED_CHANNELS_COUNTER;
use futures::{
channel::mpsc::{
self, SendError, TryRecvError, TrySendError, UnboundedReceiver, UnboundedSender,
},
sink::Sink,
stream::{FusedStream, Stream},
task::{Context, Poll},
};
use std::pin::Pin;
/// Wrapper Type around `UnboundedSender` that increases the global
/// measure when a message is added
@@ -61,9 +65,11 @@ mod inner {
/// Wrapper around `mpsc::unbounded` that tracks the in- and outflow via
/// `UNBOUNDED_CHANNELS_COUNTER`
pub fn tracing_unbounded<T>(key: &'static str) ->(TracingUnboundedSender<T>, TracingUnboundedReceiver<T>) {
pub fn tracing_unbounded<T>(
key: &'static str,
) -> (TracingUnboundedSender<T>, TracingUnboundedReceiver<T>) {
let (s, r) = mpsc::unbounded();
(TracingUnboundedSender(key, s), TracingUnboundedReceiver(key,r))
(TracingUnboundedSender(key, s), TracingUnboundedReceiver(key, r))
}
impl<T> TracingUnboundedSender<T> {
@@ -94,7 +100,7 @@ mod inner {
/// Proxy function to mpsc::UnboundedSender
pub fn unbounded_send(&self, msg: T) -> Result<(), TrySendError<T>> {
self.1.unbounded_send(msg).map(|s|{
self.1.unbounded_send(msg).map(|s| {
UNBOUNDED_CHANNELS_COUNTER.with_label_values(&[self.0, &"send"]).inc();
s
})
@@ -107,25 +113,25 @@ mod inner {
}
impl<T> TracingUnboundedReceiver<T> {
fn consume(&mut self) {
// consume all items, make sure to reflect the updated count
let mut count = 0;
loop {
if self.1.is_terminated() {
break;
break
}
match self.try_next() {
Ok(Some(..)) => count += 1,
_ => break
_ => break,
}
}
// and discount the messages
if count > 0 {
UNBOUNDED_CHANNELS_COUNTER.with_label_values(&[self.0, &"dropped"]).inc_by(count);
UNBOUNDED_CHANNELS_COUNTER
.with_label_values(&[self.0, &"dropped"])
.inc_by(count);
}
}
/// Proxy function to mpsc::UnboundedReceiver
@@ -158,21 +164,16 @@ mod inner {
impl<T> Stream for TracingUnboundedReceiver<T> {
type Item = T;
fn poll_next(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Option<T>> {
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<T>> {
let s = self.get_mut();
match Pin::new(&mut s.1).poll_next(cx) {
Poll::Ready(msg) => {
if msg.is_some() {
UNBOUNDED_CHANNELS_COUNTER.with_label_values(&[s.0, "received"]).inc();
}
}
Poll::Ready(msg)
}
Poll::Pending => {
Poll::Pending
}
},
Poll::Pending => Poll::Pending,
}
}
}
@@ -186,24 +187,15 @@ mod inner {
impl<T> Sink<T> for TracingUnboundedSender<T> {
type Error = SendError;
fn poll_ready(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Result<(), Self::Error>> {
fn poll_ready(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
TracingUnboundedSender::poll_ready(&*self, cx)
}
fn start_send(
mut self: Pin<&mut Self>,
msg: T,
) -> Result<(), Self::Error> {
fn start_send(mut self: Pin<&mut Self>, msg: T) -> Result<(), Self::Error> {
TracingUnboundedSender::start_send(&mut *self, msg)
}
fn poll_flush(
self: Pin<&mut Self>,
_: &mut Context<'_>,
) -> Poll<Result<(), Self::Error>> {
fn poll_flush(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}
@@ -219,33 +211,23 @@ mod inner {
impl<T> Sink<T> for &TracingUnboundedSender<T> {
type Error = SendError;
fn poll_ready(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Result<(), Self::Error>> {
fn poll_ready(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
TracingUnboundedSender::poll_ready(*self, cx)
}
fn start_send(self: Pin<&mut Self>, msg: T) -> Result<(), Self::Error> {
self.unbounded_send(msg)
.map_err(TrySendError::into_send_error)
self.unbounded_send(msg).map_err(TrySendError::into_send_error)
}
fn poll_flush(
self: Pin<&mut Self>,
_: &mut Context<'_>,
) -> Poll<Result<(), Self::Error>> {
fn poll_flush(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}
fn poll_close(
self: Pin<&mut Self>,
_: &mut Context<'_>,
) -> Poll<Result<(), Self::Error>> {
fn poll_close(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
self.close_channel();
Poll::Ready(Ok(()))
}
}
}
pub use inner::{tracing_unbounded, TracingUnboundedSender, TracingUnboundedReceiver};
pub use inner::{tracing_unbounded, TracingUnboundedReceiver, TracingUnboundedSender};
+16 -13
View File
@@ -16,9 +16,13 @@
// limitations under the License.
use crate::mpsc::{tracing_unbounded, TracingUnboundedReceiver, TracingUnboundedSender};
use futures::{prelude::*, lock::Mutex};
use futures::{lock::Mutex, prelude::*};
use futures_timer::Delay;
use std::{pin::Pin, task::{Poll, Context}, time::Duration};
use std::{
pin::Pin,
task::{Context, Poll},
time::Duration,
};
/// Holds a list of `UnboundedSender`s, each associated with a certain time period. Every time the
/// period elapses, we push an element on the sender.
@@ -44,7 +48,7 @@ struct YieldAfter<T> {
sender: Option<TracingUnboundedSender<T>>,
}
impl <T> Default for StatusSinks<T> {
impl<T> Default for StatusSinks<T> {
fn default() -> Self {
Self::new()
}
@@ -56,10 +60,7 @@ impl<T> StatusSinks<T> {
let (entries_tx, entries_rx) = tracing_unbounded("status-sinks-entries");
StatusSinks {
inner: Mutex::new(Inner {
entries: stream::FuturesUnordered::new(),
entries_rx,
}),
inner: Mutex::new(Inner { entries: stream::FuturesUnordered::new(), entries_rx }),
entries_tx,
}
}
@@ -100,7 +101,7 @@ impl<T> StatusSinks<T> {
}
};
futures::select!{
futures::select! {
new_entry = inner.entries_rx.next() => {
if let Some(new_entry) = new_entry {
inner.entries.push(new_entry);
@@ -149,7 +150,7 @@ impl<'a, T> Drop for ReadySinkEvent<'a, T> {
fn drop(&mut self) {
if let Some(sender) = self.sender.take() {
if sender.is_closed() {
return;
return
}
let _ = self.sinks.entries_tx.unbounded_send(YieldAfter {
@@ -170,18 +171,20 @@ impl<T> futures::Future for YieldAfter<T> {
match Pin::new(&mut this.delay).poll(cx) {
Poll::Pending => Poll::Pending,
Poll::Ready(()) => {
let sender = this.sender.take()
let sender = this
.sender
.take()
.expect("sender is always Some unless the future is finished; qed");
Poll::Ready((sender, this.interval))
}
},
}
}
}
#[cfg(test)]
mod tests {
use crate::mpsc::tracing_unbounded;
use super::StatusSinks;
use crate::mpsc::tracing_unbounded;
use futures::prelude::*;
use std::time::Duration;
@@ -208,7 +211,7 @@ mod tests {
Box::pin(async {
let items: Vec<i32> = rx.take(3).collect().await;
assert_eq!(items, [6, 7, 8]);
})
}),
));
}
}