misc: clippy fixes (#126)

This commit is contained in:
Bruce Mitchener 2019-07-01 08:26:15 +07:00 committed by Toby Lawrence
parent 668fc877a6
commit 90b0c6b347
3 changed files with 14 additions and 12 deletions

View File

@ -508,6 +508,12 @@ impl FieldSet {
pub fn len(&self) -> usize { pub fn len(&self) -> usize {
self.names.len() self.names.len()
} }
/// Returns whether or not this `FieldSet` has fields.
#[inline]
pub fn is_empty(&self) -> bool {
self.names.is_empty()
}
} }
impl<'a> IntoIterator for &'a FieldSet { impl<'a> IntoIterator for &'a FieldSet {
@ -531,7 +537,7 @@ impl fmt::Debug for FieldSet {
impl fmt::Display for FieldSet { impl fmt::Display for FieldSet {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_set() f.debug_set()
.entries(self.names.iter().map(|n| display(n))) .entries(self.names.iter().map(display))
.finish() .finish()
} }
} }

View File

@ -1,10 +1,7 @@
//! Subscribers collect and record trace data. //! Subscribers collect and record trace data.
use crate::{span, Event, Metadata}; use crate::{span, Event, Metadata};
use std::{ use std::any::{Any, TypeId};
any::{Any, TypeId},
ptr,
};
/// Trait representing the functions required to collect trace data. /// Trait representing the functions required to collect trace data.
/// ///
@ -109,9 +106,10 @@ pub trait Subscriber: 'static {
/// [`enabled`]: #method.enabled /// [`enabled`]: #method.enabled
/// [`rebuild_interest_cache`]: ../callsite/fn.rebuild_interest_cache.html /// [`rebuild_interest_cache`]: ../callsite/fn.rebuild_interest_cache.html
fn register_callsite(&self, metadata: &'static Metadata<'static>) -> Interest { fn register_callsite(&self, metadata: &'static Metadata<'static>) -> Interest {
match self.enabled(metadata) { if self.enabled(metadata) {
true => Interest::always(), Interest::always()
false => Interest::never(), } else {
Interest::never()
} }
} }
@ -363,7 +361,7 @@ impl dyn Subscriber {
pub fn downcast_ref<T: Any>(&self) -> Option<&T> { pub fn downcast_ref<T: Any>(&self) -> Option<&T> {
unsafe { unsafe {
let raw = self.downcast_raw(TypeId::of::<T>())?; let raw = self.downcast_raw(TypeId::of::<T>())?;
if raw == ptr::null() { if raw.is_null() {
None None
} else { } else {
Some(&*(raw as *const _)) Some(&*(raw as *const _))

View File

@ -57,9 +57,7 @@ impl EnvFilter {
/// Returns a new `EnvFilter` from the value of the given environment /// Returns a new `EnvFilter` from the value of the given environment
/// variable, ignoring any invalid filter directives. /// variable, ignoring any invalid filter directives.
pub fn from_env<A: AsRef<str>>(env: A) -> Self { pub fn from_env<A: AsRef<str>>(env: A) -> Self {
env::var(env.as_ref()) env::var(env.as_ref()).map(Self::new).unwrap_or_default()
.map(|ref var| Self::new(var))
.unwrap_or_default()
} }
/// Returns a new `EnvFilter` from the directives in the given string, /// Returns a new `EnvFilter` from the directives in the given string,