Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Minor cleanups
  • Loading branch information
JohnTitor committed Jun 29, 2021
1 parent 50f8a0d commit 8868d08
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 43 deletions.
14 changes: 7 additions & 7 deletions phf/src/map.rs
Expand Up @@ -27,7 +27,7 @@ where
K: fmt::Debug,
V: fmt::Debug,
{
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_map().entries(self.entries()).finish()
}
}
Expand Down Expand Up @@ -108,7 +108,7 @@ impl<K, V> Map<K, V> {
/// Returns an iterator over the key/value pairs in the map.
///
/// Entries are returned in an arbitrary but fixed order.
pub fn entries(&self) -> Entries<K, V> {
pub fn entries(&self) -> Entries<'_, K, V> {
Entries {
iter: self.entries.iter(),
}
Expand All @@ -117,7 +117,7 @@ impl<K, V> Map<K, V> {
/// Returns an iterator over the keys in the map.
///
/// Keys are returned in an arbitrary but fixed order.
pub fn keys(&self) -> Keys<K, V> {
pub fn keys(&self) -> Keys<'_, K, V> {
Keys {
iter: self.entries(),
}
Expand All @@ -126,7 +126,7 @@ impl<K, V> Map<K, V> {
/// Returns an iterator over the values in the map.
///
/// Values are returned in an arbitrary but fixed order.
pub fn values(&self) -> Values<K, V> {
pub fn values(&self) -> Values<'_, K, V> {
Values {
iter: self.entries(),
}
Expand All @@ -143,7 +143,7 @@ impl<'a, K, V> IntoIterator for &'a Map<K, V> {
}

/// An iterator over the key/value pairs in a `Map`.
pub struct Entries<'a, K: 'a, V: 'a> {
pub struct Entries<'a, K, V> {
iter: slice::Iter<'a, (K, V)>,
}

Expand All @@ -168,7 +168,7 @@ impl<'a, K, V> DoubleEndedIterator for Entries<'a, K, V> {
impl<'a, K, V> ExactSizeIterator for Entries<'a, K, V> {}

/// An iterator over the keys in a `Map`.
pub struct Keys<'a, K: 'a, V: 'a> {
pub struct Keys<'a, K, V> {
iter: Entries<'a, K, V>,
}

Expand All @@ -193,7 +193,7 @@ impl<'a, K, V> DoubleEndedIterator for Keys<'a, K, V> {
impl<'a, K, V> ExactSizeIterator for Keys<'a, K, V> {}

/// An iterator over the values in a `Map`.
pub struct Values<'a, K: 'a, V: 'a> {
pub struct Values<'a, K, V> {
iter: Entries<'a, K, V>,
}

Expand Down
14 changes: 7 additions & 7 deletions phf/src/ordered_map.rs
Expand Up @@ -33,7 +33,7 @@ where
K: fmt::Debug,
V: fmt::Debug,
{
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_map().entries(self.entries()).finish()
}
}
Expand Down Expand Up @@ -140,7 +140,7 @@ impl<K, V> OrderedMap<K, V> {
/// Returns an iterator over the key/value pairs in the map.
///
/// Entries are returned in the same order in which they were defined.
pub fn entries(&self) -> Entries<K, V> {
pub fn entries(&self) -> Entries<'_, K, V> {
Entries {
iter: self.entries.iter(),
}
Expand All @@ -149,7 +149,7 @@ impl<K, V> OrderedMap<K, V> {
/// Returns an iterator over the keys in the map.
///
/// Keys are returned in the same order in which they were defined.
pub fn keys(&self) -> Keys<K, V> {
pub fn keys(&self) -> Keys<'_, K, V> {
Keys {
iter: self.entries(),
}
Expand All @@ -158,7 +158,7 @@ impl<K, V> OrderedMap<K, V> {
/// Returns an iterator over the values in the map.
///
/// Values are returned in the same order in which they were defined.
pub fn values(&self) -> Values<K, V> {
pub fn values(&self) -> Values<'_, K, V> {
Values {
iter: self.entries(),
}
Expand All @@ -175,7 +175,7 @@ impl<'a, K, V> IntoIterator for &'a OrderedMap<K, V> {
}

/// An iterator over the entries in a `OrderedMap`.
pub struct Entries<'a, K: 'a, V: 'a> {
pub struct Entries<'a, K, V> {
iter: slice::Iter<'a, (K, V)>,
}

Expand All @@ -200,7 +200,7 @@ impl<'a, K, V> DoubleEndedIterator for Entries<'a, K, V> {
impl<'a, K, V> ExactSizeIterator for Entries<'a, K, V> {}

/// An iterator over the keys in a `OrderedMap`.
pub struct Keys<'a, K: 'a, V: 'a> {
pub struct Keys<'a, K, V> {
iter: Entries<'a, K, V>,
}

Expand All @@ -225,7 +225,7 @@ impl<'a, K, V> DoubleEndedIterator for Keys<'a, K, V> {
impl<'a, K, V> ExactSizeIterator for Keys<'a, K, V> {}

/// An iterator over the values in a `OrderedMap`.
pub struct Values<'a, K: 'a, V: 'a> {
pub struct Values<'a, K, V> {
iter: Entries<'a, K, V>,
}

Expand Down
6 changes: 3 additions & 3 deletions phf/src/ordered_set.rs
Expand Up @@ -23,7 +23,7 @@ impl<T> fmt::Debug for OrderedSet<T>
where
T: fmt::Debug,
{
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_set().entries(self).finish()
}
}
Expand Down Expand Up @@ -79,7 +79,7 @@ impl<T> OrderedSet<T> {
/// Returns an iterator over the values in the set.
///
/// Values are returned in the same order in which they were defined.
pub fn iter(&self) -> Iter<T> {
pub fn iter(&self) -> Iter<'_, T> {
Iter {
iter: self.map.keys(),
}
Expand Down Expand Up @@ -119,7 +119,7 @@ impl<'a, T> IntoIterator for &'a OrderedSet<T> {
}

/// An iterator over the values in a `OrderedSet`.
pub struct Iter<'a, T: 'a> {
pub struct Iter<'a, T> {
iter: ordered_map::Keys<'a, T, ()>,
}

Expand Down
4 changes: 2 additions & 2 deletions phf/src/set.rs
Expand Up @@ -22,7 +22,7 @@ impl<T> fmt::Debug for Set<T>
where
T: fmt::Debug,
{
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_set().entries(self).finish()
}
}
Expand Down Expand Up @@ -62,7 +62,7 @@ impl<T> Set<T> {
/// Returns an iterator over the values in the set.
///
/// Values are returned in an arbitrary but fixed order.
pub fn iter(&self) -> Iter<T> {
pub fn iter(&self) -> Iter<'_, T> {
Iter {
iter: self.map.keys(),
}
Expand Down
24 changes: 12 additions & 12 deletions phf_codegen/src/lib.rs
Expand Up @@ -135,7 +135,7 @@ use phf_generator::HashState;
struct Delegate<T>(T);

impl<T: FmtConst> fmt::Display for Delegate<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt_const(f)
}
}
Expand Down Expand Up @@ -188,7 +188,7 @@ impl<K: Hash + PhfHash + Eq + FmtConst> Map<K> {
/// # Panics
///
/// Panics if there are any duplicate keys.
pub fn build(&self) -> DisplayMap<K> {
pub fn build(&self) -> DisplayMap<'_, K> {
let mut set = HashSet::new();
for key in &self.keys {
if !set.insert(key) {
Expand Down Expand Up @@ -216,7 +216,7 @@ pub struct DisplayMap<'a, K> {
}

impl<'a, K: FmtConst + 'a> fmt::Display for DisplayMap<'a, K> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// funky formatting here for nice output
write!(
f,
Expand Down Expand Up @@ -293,20 +293,20 @@ impl<T: Hash + PhfHash + Eq + FmtConst> Set<T> {
/// # Panics
///
/// Panics if there are any duplicate keys.
pub fn build(&self) -> DisplaySet<T> {
pub fn build(&self) -> DisplaySet<'_, T> {
DisplaySet {
inner: self.map.build(),
}
}
}

/// An adapter for printing a [`Set`](Set).
pub struct DisplaySet<'a, T: 'a> {
pub struct DisplaySet<'a, T> {
inner: DisplayMap<'a, T>,
}

impl<'a, T: FmtConst + 'a> fmt::Display for DisplaySet<'a, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}::Set {{ map: {} }}", self.inner.path, self.inner)
}
}
Expand Down Expand Up @@ -350,7 +350,7 @@ impl<K: Hash + PhfHash + Eq + FmtConst> OrderedMap<K> {
/// # Panics
///
/// Panics if there are any duplicate keys.
pub fn build(&self) -> DisplayOrderedMap<K> {
pub fn build(&self) -> DisplayOrderedMap<'_, K> {
let mut set = HashSet::new();
for key in &self.keys {
if !set.insert(key) {
Expand All @@ -370,15 +370,15 @@ impl<K: Hash + PhfHash + Eq + FmtConst> OrderedMap<K> {
}

/// An adapter for printing a [`OrderedMap`](OrderedMap).
pub struct DisplayOrderedMap<'a, K: 'a> {
pub struct DisplayOrderedMap<'a, K> {
path: &'a str,
state: HashState,
keys: &'a [K],
values: &'a [String],
}

impl<'a, K: FmtConst + 'a> fmt::Display for DisplayOrderedMap<'a, K> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{}::OrderedMap {{
Expand Down Expand Up @@ -466,20 +466,20 @@ impl<T: Hash + PhfHash + Eq + FmtConst> OrderedSet<T> {
/// # Panics
///
/// Panics if there are any duplicate keys.
pub fn build(&self) -> DisplayOrderedSet<T> {
pub fn build(&self) -> DisplayOrderedSet<'_, T> {
DisplayOrderedSet {
inner: self.map.build(),
}
}
}

/// An adapter for printing a [`OrderedSet`](OrderedSet).
pub struct DisplayOrderedSet<'a, T: 'a> {
pub struct DisplayOrderedSet<'a, T> {
inner: DisplayOrderedMap<'a, T>,
}

impl<'a, T: FmtConst + 'a> fmt::Display for DisplayOrderedSet<'a, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{}::OrderedSet {{ map: {} }}",
Expand Down
9 changes: 5 additions & 4 deletions phf_macros/src/lib.rs
@@ -1,3 +1,4 @@
// FIXME: Remove `extern crate` below when we bump MSRV to 1.42 or higher.
extern crate proc_macro;

use phf_generator::HashState;
Expand Down Expand Up @@ -174,7 +175,7 @@ impl PhfHash for Key {
}

impl Parse for Key {
fn parse(input: ParseStream) -> parse::Result<Key> {
fn parse(input: ParseStream<'_>) -> parse::Result<Key> {
let expr = input.parse()?;
let parsed = ParsedKey::from_expr(&expr)
.ok_or_else(|| Error::new_spanned(&expr, "unsupported key expression"))?;
Expand All @@ -198,7 +199,7 @@ impl PhfHash for Entry {
}

impl Parse for Entry {
fn parse(input: ParseStream) -> parse::Result<Entry> {
fn parse(input: ParseStream<'_>) -> parse::Result<Entry> {
let key = input.parse()?;
input.parse::<Token![=>]>()?;
let value = input.parse()?;
Expand All @@ -209,7 +210,7 @@ impl Parse for Entry {
struct Map(Vec<Entry>);

impl Parse for Map {
fn parse(input: ParseStream) -> parse::Result<Map> {
fn parse(input: ParseStream<'_>) -> parse::Result<Map> {
let parsed = Punctuated::<Entry, Token![,]>::parse_terminated(input)?;
let map = parsed.into_iter().collect::<Vec<_>>();
check_duplicates(&map)?;
Expand All @@ -220,7 +221,7 @@ impl Parse for Map {
struct Set(Vec<Entry>);

impl Parse for Set {
fn parse(input: ParseStream) -> parse::Result<Set> {
fn parse(input: ParseStream<'_>) -> parse::Result<Set> {
let parsed = Punctuated::<Key, Token![,]>::parse_terminated(input)?;
let set = parsed
.into_iter()
Expand Down
16 changes: 8 additions & 8 deletions phf_shared/src/lib.rs
Expand Up @@ -78,7 +78,7 @@ pub trait PhfHash {
/// Trait for printing types with `const` constructors, used by `phf_codegen` and `phf_macros`.
pub trait FmtConst {
/// Print a `const` expression representing this value.
fn fmt_const(&self, f: &mut fmt::Formatter) -> fmt::Result;
fn fmt_const(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result;
}

/// Identical to `std::borrow::Borrow` except omitting blanket impls to facilitate other
Expand Down Expand Up @@ -131,7 +131,7 @@ pub trait PhfBorrow<B: ?Sized> {
macro_rules! delegate_debug (
($ty:ty) => {
impl FmtConst for $ty {
fn fmt_const(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt_const(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self)
}
}
Expand Down Expand Up @@ -220,7 +220,7 @@ impl<'a, T: 'a + PhfHash + ?Sized> PhfHash for &'a T {
}

impl<'a, T: 'a + FmtConst + ?Sized> FmtConst for &'a T {
fn fmt_const(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt_const(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
(*self).fmt_const(f)
}
}
Expand Down Expand Up @@ -253,7 +253,7 @@ impl PhfHash for [u8] {

impl FmtConst for [u8] {
#[inline]
fn fmt_const(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt_const(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// slices need a leading reference
write!(f, "&{:?}", self)
}
Expand All @@ -275,7 +275,7 @@ impl<S> FmtConst for unicase::UniCase<S>
where
S: AsRef<str>,
{
fn fmt_const(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt_const(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if self.is_ascii() {
f.write_str("UniCase::ascii(")?;
} else {
Expand Down Expand Up @@ -304,7 +304,7 @@ impl PhfHash for uncased::UncasedStr {

#[cfg(feature = "uncased")]
impl FmtConst for uncased::UncasedStr {
fn fmt_const(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt_const(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// transmute is not stable in const fns (rust-lang/rust#53605), so
// `UncasedStr::new` can't be a const fn itself, but we can inline the
// call to transmute here in the meantime.
Expand Down Expand Up @@ -360,7 +360,7 @@ impl PhfHash for char {
}

// minimize duplicated code since formatting drags in quite a bit
fn fmt_array(array: &[u8], f: &mut fmt::Formatter) -> fmt::Result {
fn fmt_array(array: &[u8], f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", array)
}

Expand All @@ -374,7 +374,7 @@ macro_rules! array_impl (
}

impl FmtConst for [$t; $n] {
fn fmt_const(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt_const(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt_array(self, f)
}
}
Expand Down

0 comments on commit 8868d08

Please sign in to comment.