From 58e222380b7fc9609a055cb5a6110ba04e47d677 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sat, 31 Oct 2015 22:59:11 -0700 Subject: [PATCH] Run through rustfmt --- phf/src/map.rs | 27 +++++++++++----- phf/src/ordered_map.rs | 35 +++++++++++++++------ phf/src/ordered_set.rs | 18 ++++++++--- phf/src/set.rs | 16 +++++++--- phf_codegen/src/lib.rs | 66 ++++++++++++++++++++++++---------------- phf_generator/src/lib.rs | 34 ++++++++++++--------- phf_macros/src/lib.rs | 57 +++++++++++++++++++++------------- phf_macros/src/util.rs | 63 ++++++++++++++++++++++++-------------- phf_shared/src/lib.rs | 4 ++- 9 files changed, 208 insertions(+), 112 deletions(-) diff --git a/phf/src/map.rs b/phf/src/map.rs index 663b78d9..d2e33554 100644 --- a/phf/src/map.rs +++ b/phf/src/map.rs @@ -14,7 +14,7 @@ use phf_shared; /// The fields of this struct are public so that they may be initialized by the /// `phf_map!` macro and code generation. They are subject to change at any /// time and should never be accessed directly. -pub struct Map { +pub struct Map { #[doc(hidden)] pub key: u64, #[doc(hidden)] @@ -49,12 +49,18 @@ impl Map { } /// Determines if `key` is in the `Map`. - pub fn contains_key(&self, key: &T) -> bool where T: Eq + PhfHash, K: Borrow { + pub fn contains_key(&self, key: &T) -> bool + where T: Eq + PhfHash, + K: Borrow + { self.get(key).is_some() } /// Returns a reference to the value that `key` maps to. - pub fn get(&self, key: &T) -> Option<&V> where T: Eq + PhfHash, K: Borrow { + pub fn get(&self, key: &T) -> Option<&V> + where T: Eq + PhfHash, + K: Borrow + { self.get_entry(key).map(|e| e.1) } @@ -62,13 +68,18 @@ impl Map { /// key. /// /// This can be useful for interning schemes. - pub fn get_key(&self, key: &T) -> Option<&K> where T: Eq + PhfHash, K: Borrow { + pub fn get_key(&self, key: &T) -> Option<&K> + where T: Eq + PhfHash, + K: Borrow + { self.get_entry(key).map(|e| e.0) } /// Like `get`, but returns both the key and the value. pub fn get_entry(&self, key: &T) -> Option<(&K, &V)> - where T: Eq + PhfHash, K: Borrow { + where T: Eq + PhfHash, + K: Borrow + { let hash = phf_shared::hash(key, self.key); let index = phf_shared::get_index(hash, self.disps, self.entries.len()); let entry = &self.entries[index as usize]; @@ -112,7 +123,7 @@ impl<'a, K, V> IntoIterator for &'a Map { } /// An iterator over the key/value pairs in a `Map`. -pub struct Entries<'a, K:'a, V:'a> { +pub struct Entries<'a, K: 'a, V: 'a> { iter: slice::Iter<'a, (K, V)>, } @@ -137,7 +148,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: 'a, V: 'a> { iter: Entries<'a, K, V>, } @@ -162,7 +173,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: 'a, V: 'a> { iter: Entries<'a, K, V>, } diff --git a/phf/src/ordered_map.rs b/phf/src/ordered_map.rs index 85400f98..6d2f85f4 100644 --- a/phf/src/ordered_map.rs +++ b/phf/src/ordered_map.rs @@ -18,7 +18,7 @@ use phf_shared; /// The fields of this struct are public so that they may be initialized by the /// `phf_ordered_map!` macro and code generation. They are subject to change at /// any time and should never be accessed directly. -pub struct OrderedMap { +pub struct OrderedMap { #[doc(hidden)] pub key: u64, #[doc(hidden)] @@ -55,7 +55,10 @@ impl OrderedMap { } /// Returns a reference to the value that `key` maps to. - pub fn get(&self, key: &T) -> Option<&V> where T: Eq + PhfHash, K: Borrow { + pub fn get(&self, key: &T) -> Option<&V> + where T: Eq + PhfHash, + K: Borrow + { self.get_entry(key).map(|e| e.1) } @@ -63,19 +66,27 @@ impl OrderedMap { /// key. /// /// This can be useful for interning schemes. - pub fn get_key(&self, key: &T) -> Option<&K> where T: Eq + PhfHash, K: Borrow { + pub fn get_key(&self, key: &T) -> Option<&K> + where T: Eq + PhfHash, + K: Borrow + { self.get_entry(key).map(|e| e.0) } /// Determines if `key` is in the `Map`. - pub fn contains_key(&self, key: &T) -> bool where T: Eq + PhfHash, K: Borrow { + pub fn contains_key(&self, key: &T) -> bool + where T: Eq + PhfHash, + K: Borrow + { self.get(key).is_some() } /// Returns the index of the key within the list used to initialize /// the ordered map. pub fn get_index(&self, key: &T) -> Option - where T: Eq + PhfHash, K: Borrow { + where T: Eq + PhfHash, + K: Borrow + { self.get_internal(key).map(|(i, _)| i) } @@ -87,12 +98,16 @@ impl OrderedMap { /// Like `get`, but returns both the key and the value. pub fn get_entry(&self, key: &T) -> Option<(&K, &V)> - where T: Eq + PhfHash, K: Borrow { + where T: Eq + PhfHash, + K: Borrow + { self.get_internal(key).map(|(_, e)| e) } fn get_internal(&self, key: &T) -> Option<(usize, (&K, &V))> - where T: Eq + PhfHash, K: Borrow { + where T: Eq + PhfHash, + K: Borrow + { let hash = phf_shared::hash(key, self.key); let idx_index = phf_shared::get_index(hash, self.disps, self.idxs.len()); let idx = self.idxs[idx_index as usize]; @@ -138,7 +153,7 @@ impl<'a, K, V> IntoIterator for &'a OrderedMap { } /// An iterator over the entries in a `OrderedMap`. -pub struct Entries<'a, K:'a, V:'a> { +pub struct Entries<'a, K: 'a, V: 'a> { iter: slice::Iter<'a, (K, V)>, } @@ -163,7 +178,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: 'a, V: 'a> { iter: Entries<'a, K, V>, } @@ -188,7 +203,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: 'a, V: 'a> { iter: Entries<'a, K, V>, } diff --git a/phf/src/ordered_set.rs b/phf/src/ordered_set.rs index 68ae3953..bcd986c2 100644 --- a/phf/src/ordered_set.rs +++ b/phf/src/ordered_set.rs @@ -15,7 +15,7 @@ use {PhfHash, OrderedMap}; /// The fields of this struct are public so that they may be initialized by the /// `phf_ordered_set!` macro and code generation. They are subject to change at /// any time and should never be accessed directly. -pub struct OrderedSet { +pub struct OrderedSet { #[doc(hidden)] pub map: OrderedMap, } @@ -41,14 +41,19 @@ impl OrderedSet { /// key. /// /// This can be useful for interning schemes. - pub fn get_key(&self, key: &U) -> Option<&T> where U: Eq + PhfHash, T: Borrow { + pub fn get_key(&self, key: &U) -> Option<&T> + where U: Eq + PhfHash, + T: Borrow + { self.map.get_key(key) } /// Returns the index of the key within the list used to initialize /// the ordered set. pub fn get_index(&self, key: &U) -> Option - where U: Eq + PhfHash, T: Borrow { + where U: Eq + PhfHash, + T: Borrow + { self.map.get_index(key) } @@ -59,7 +64,10 @@ impl OrderedSet { } /// Returns true if `value` is in the `Set`. - pub fn contains(&self, value: &U) -> bool where U: Eq + PhfHash, T: Borrow { + pub fn contains(&self, value: &U) -> bool + where U: Eq + PhfHash, + T: Borrow + { self.map.contains_key(value) } @@ -101,7 +109,7 @@ impl<'a, T> IntoIterator for &'a OrderedSet { } /// An iterator over the values in a `OrderedSet`. -pub struct Iter<'a, T:'a> { +pub struct Iter<'a, T: 'a> { iter: ordered_map::Keys<'a, T, ()>, } diff --git a/phf/src/set.rs b/phf/src/set.rs index bb7a9d73..04ed9a00 100644 --- a/phf/src/set.rs +++ b/phf/src/set.rs @@ -14,9 +14,9 @@ use Map; /// The fields of this struct are public so that they may be initialized by the /// `phf_set!` macro and code generation. They are subject to change at any /// time and should never be accessed directly. -pub struct Set { +pub struct Set { #[doc(hidden)] - pub map: Map + pub map: Map, } impl fmt::Debug for Set where T: fmt::Debug { @@ -40,12 +40,18 @@ impl Set { /// key. /// /// This can be useful for interning schemes. - pub fn get_key(&self, key: &U) -> Option<&T> where U: Eq + PhfHash, T: Borrow { + pub fn get_key(&self, key: &U) -> Option<&T> + where U: Eq + PhfHash, + T: Borrow + { self.map.get_key(key) } /// Returns true if `value` is in the `Set`. - pub fn contains(&self, value: &U) -> bool where U: Eq + PhfHash, T: Borrow { + pub fn contains(&self, value: &U) -> bool + where U: Eq + PhfHash, + T: Borrow + { self.map.contains_key(value) } @@ -84,7 +90,7 @@ impl<'a, T> IntoIterator for &'a Set { } /// An iterator over the values in a `Set`. -pub struct Iter<'a, T:'static> { +pub struct Iter<'a, T: 'static> { iter: map::Keys<'a, T, ()>, } diff --git a/phf_codegen/src/lib.rs b/phf_codegen/src/lib.rs index db5d6c3d..9532d279 100644 --- a/phf_codegen/src/lib.rs +++ b/phf_codegen/src/lib.rs @@ -21,7 +21,8 @@ //! let path = Path::new(&env::var("OUT_DIR").unwrap()).join("codegen.rs"); //! let mut file = BufWriter::new(File::create(&path).unwrap()); //! -//! write!(&mut file, "static KEYWORDS: phf::Map<&'static str, Keyword> = ").unwrap(); +//! write!(&mut file, "static KEYWORDS: phf::Map<&'static str, Keyword> = +//! ").unwrap(); //! phf_codegen::Map::new() //! .entry("loop", "Keyword::Loop") //! .entry("continue", "Keyword::Continue") @@ -104,7 +105,8 @@ impl Map { // the linker ends up throwing a way a bunch of static symbols we actually need. // This works around the problem, assuming that all clients call `Map::new` by // calling a non-generic function. - fn noop_fix_for_27438() { } + fn noop_fix_for_27438() { + } noop_fix_for_27438(); Map { @@ -137,24 +139,31 @@ impl Map { let state = phf_generator::generate_hash(&self.keys); - try!(write!(w, "::phf::Map {{ + try!(write!(w, + "::phf::Map {{ key: {}, disps: &[", state.key)); for &(d1, d2) in &state.disps { - try!(write!(w, " + try!(write!(w, + " ({}, {}),", - d1, d2)); + d1, + d2)); } - try!(write!(w, " + try!(write!(w, + " ], entries: &[")); for &idx in &state.map { - try!(write!(w, " + try!(write!(w, + " ({:?}, {}),", - &self.keys[idx], &self.values[idx])); + &self.keys[idx], + &self.values[idx])); } - write!(w, " + write!(w, + " ] }}") } @@ -162,15 +171,13 @@ impl Map { /// A builder for the `phf::Set` type. pub struct Set { - map: Map + map: Map, } impl Set { /// Constructs a new `phf::Set` builder. pub fn new() -> Set { - Set { - map: Map::new() - } + Set { map: Map::new() } } /// Adds an entry to the builder. @@ -231,32 +238,41 @@ impl OrderedMap { let state = phf_generator::generate_hash(&self.keys); - try!(write!(w, "::phf::OrderedMap {{ + try!(write!(w, + "::phf::OrderedMap {{ key: {}, disps: &[", state.key)); for &(d1, d2) in &state.disps { - try!(write!(w, " + try!(write!(w, + " ({}, {}),", - d1, d2)); + d1, + d2)); } - try!(write!(w, " + try!(write!(w, + " ], idxs: &[")); for &idx in &state.map { - try!(write!(w, " + try!(write!(w, + " {},", idx)); } - try!(write!(w, " + try!(write!(w, + " ], entries: &[")); for (key, value) in self.keys.iter().zip(self.values.iter()) { - try!(write!(w, " + try!(write!(w, + " ({:?}, {}),", - key, value)); + key, + value)); } - write!(w, " + write!(w, + " ] }}") } @@ -264,15 +280,13 @@ impl OrderedMap { /// A builder for the `phf::OrderedSet` type. pub struct OrderedSet { - map: OrderedMap + map: OrderedMap, } impl OrderedSet { /// Constructs a new `phf::OrderedSet` builder. pub fn new() -> OrderedSet { - OrderedSet { - map: OrderedMap::new() - } + OrderedSet { map: OrderedMap::new() } } /// Adds an entry to the builder. diff --git a/phf_generator/src/lib.rs b/phf_generator/src/lib.rs index 4dc610aa..d8bb1a89 100644 --- a/phf_generator/src/lib.rs +++ b/phf_generator/src/lib.rs @@ -38,20 +38,27 @@ fn try_generate_hash(entries: &[H], rng: &mut XorShiftRng) -> Option let key = rng.gen(); - let hashes: Vec<_> = entries.iter().map(|entry| { - let hash = phf_shared::hash(entry, key); - let (g, f1, f2) = phf_shared::split(hash); - Hashes { - g: g, - f1: f1, - f2: f2 - } - }).collect(); + let hashes: Vec<_> = entries.iter() + .map(|entry| { + let hash = phf_shared::hash(entry, key); + let (g, f1, f2) = phf_shared::split(hash); + Hashes { + g: g, + f1: f1, + f2: f2, + } + }) + .collect(); let buckets_len = (entries.len() + DEFAULT_LAMBDA - 1) / DEFAULT_LAMBDA; let mut buckets = (0..buckets_len) - .map(|i| Bucket { idx: i, keys: vec![] }) - .collect::>(); + .map(|i| { + Bucket { + idx: i, + keys: vec![], + } + }) + .collect::>(); for (i, hash) in hashes.iter().enumerate() { buckets[(hash.g % (buckets_len as u32)) as usize].keys.push(i); @@ -86,8 +93,8 @@ fn try_generate_hash(entries: &[H], rng: &mut XorShiftRng) -> Option generation += 1; for &key in &bucket.keys { - let idx = (phf_shared::displace(hashes[key].f1, hashes[key].f2, d1, d2) - % (table_len as u32)) as usize; + let idx = (phf_shared::displace(hashes[key].f1, hashes[key].f2, d1, d2) % + (table_len as u32)) as usize; if map[idx].is_some() || try_map[idx] == generation { continue 'disps; } @@ -114,4 +121,3 @@ fn try_generate_hash(entries: &[H], rng: &mut XorShiftRng) -> Option map: map.into_iter().map(|i| i.unwrap()).collect(), }) } - diff --git a/phf_macros/src/lib.rs b/phf_macros/src/lib.rs index 2c79fe95..f08a6fe7 100644 --- a/phf_macros/src/lib.rs +++ b/phf_macros/src/lib.rs @@ -44,9 +44,7 @@ use std::collections::HashMap; use std::collections::hash_map::Entry::{Occupied, Vacant}; use syntax::ast::{self, TokenTree, LitStr, LitByteStr, LitByte, LitChar, Expr, ExprLit, ExprVec}; use syntax::codemap::{Span, Spanned}; -use syntax::ext::base::{DummyResult, - ExtCtxt, - MacResult}; +use syntax::ext::base::{DummyResult, ExtCtxt, MacResult}; use syntax::fold::Folder; use syntax::parse; use syntax::parse::token::{InternedString, Comma, Eof, FatArrow}; @@ -74,7 +72,9 @@ fn generate_hash(cx: &mut ExtCtxt, sp: Span, entries: &[Entry]) -> HashState { #[cfg(feature = "stats")] use time::precise_time_s; #[cfg(not(feature = "stats"))] - fn precise_time_s() -> f64 { 0. } + fn precise_time_s() -> f64 { + 0. + } let start = precise_time_s(); let state = phf_generator::generate_hash(entries); @@ -87,10 +87,10 @@ fn generate_hash(cx: &mut ExtCtxt, sp: Span, entries: &[Entry]) -> HashState { state } -fn expand_phf_map(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree]) -> Box { +fn expand_phf_map(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree]) -> Box { let entries = match parse_map(cx, tts) { Some(entries) => entries, - None => return DummyResult::expr(sp) + None => return DummyResult::expr(sp), }; if has_duplicates(cx, sp, &*entries) { @@ -102,10 +102,10 @@ fn expand_phf_map(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree]) -> Box Box { +fn expand_phf_set(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree]) -> Box { let entries = match parse_set(cx, tts) { Some(entries) => entries, - None => return DummyResult::expr(sp) + None => return DummyResult::expr(sp), }; if has_duplicates(cx, sp, &*entries) { @@ -117,7 +117,10 @@ fn expand_phf_set(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree]) -> Box Box { +fn expand_phf_ordered_map(cx: &mut ExtCtxt, + sp: Span, + tts: &[TokenTree]) + -> Box { let entries = match parse_map(cx, tts) { Some(entries) => entries, None => return DummyResult::expr(sp), @@ -132,10 +135,13 @@ fn expand_phf_ordered_map(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree]) -> Box< create_ordered_map(cx, sp, entries, state) } -fn expand_phf_ordered_set(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree]) -> Box { +fn expand_phf_ordered_set(cx: &mut ExtCtxt, + sp: Span, + tts: &[TokenTree]) + -> Box { let entries = match parse_set(cx, tts) { Some(entries) => entries, - None => return DummyResult::expr(sp) + None => return DummyResult::expr(sp), }; if has_duplicates(cx, sp, &*entries) { @@ -169,7 +175,7 @@ fn parse_map(cx: &mut ExtCtxt, tts: &[TokenTree]) -> Option> { entries.push(Entry { key_contents: key_contents, key: key, - value: value + value: value, }); if !parser.eat(&Comma).ok().unwrap() && parser.token != Eof { @@ -226,13 +232,20 @@ fn parse_key(cx: &mut ExtCtxt, e: &Expr) -> Option { ast::LitByte(b) => Some(Key::U8(b)), ast::LitChar(c) => Some(Key::Char(c)), ast::LitInt(i, ast::SignedIntLit(ast::TyI8, ast::Plus)) => Some(Key::I8(i as i8)), - ast::LitInt(i, ast::SignedIntLit(ast::TyI8, ast::Minus)) => Some(Key::I8(-(i as i8))), - ast::LitInt(i, ast::SignedIntLit(ast::TyI16, ast::Plus)) => Some(Key::I16(i as i16)), - ast::LitInt(i, ast::SignedIntLit(ast::TyI16, ast::Minus)) => Some(Key::I16(-(i as i16))), - ast::LitInt(i, ast::SignedIntLit(ast::TyI32, ast::Plus)) => Some(Key::I32(i as i32)), - ast::LitInt(i, ast::SignedIntLit(ast::TyI32, ast::Minus)) => Some(Key::I32(-(i as i32))), - ast::LitInt(i, ast::SignedIntLit(ast::TyI64, ast::Plus)) => Some(Key::I64(i as i64)), - ast::LitInt(i, ast::SignedIntLit(ast::TyI64, ast::Minus)) => Some(Key::I64(-(i as i64))), + ast::LitInt(i, ast::SignedIntLit(ast::TyI8, ast::Minus)) => + Some(Key::I8(-(i as i8))), + ast::LitInt(i, ast::SignedIntLit(ast::TyI16, ast::Plus)) => + Some(Key::I16(i as i16)), + ast::LitInt(i, ast::SignedIntLit(ast::TyI16, ast::Minus)) => + Some(Key::I16(-(i as i16))), + ast::LitInt(i, ast::SignedIntLit(ast::TyI32, ast::Plus)) => + Some(Key::I32(i as i32)), + ast::LitInt(i, ast::SignedIntLit(ast::TyI32, ast::Minus)) => + Some(Key::I32(-(i as i32))), + ast::LitInt(i, ast::SignedIntLit(ast::TyI64, ast::Plus)) => + Some(Key::I64(i as i64)), + ast::LitInt(i, ast::SignedIntLit(ast::TyI64, ast::Minus)) => + Some(Key::I64(-(i as i64))), ast::LitInt(i, ast::UnsignedIntLit(ast::TyU8)) => Some(Key::U8(i as u8)), ast::LitInt(i, ast::UnsignedIntLit(ast::TyU16)) => Some(Key::U16(i as u16)), ast::LitInt(i, ast::UnsignedIntLit(ast::TyU32)) => Some(Key::U32(i as u32)), @@ -258,7 +271,8 @@ fn parse_key(cx: &mut ExtCtxt, e: &Expr) -> Option { if bytes.iter().all(|x| x.is_some()) { Some(Key::Binary(std::rc::Rc::new(bytes.iter().map(|x| x.unwrap()).collect()))) } else { - cx.span_err(e.span, "not all elements of an expected u8 array literal were u8 literals"); + cx.span_err(e.span, + "not all elements of an expected u8 array literal were u8 literals"); None } } @@ -286,7 +300,8 @@ fn has_duplicates(cx: &mut ExtCtxt, sp: Span, entries: &[Entry]) -> bool { } dups = true; - cx.span_err(sp, &*format!("duplicate key {}", pprust::expr_to_string(&**key))); + cx.span_err(sp, + &*format!("duplicate key {}", pprust::expr_to_string(&**key))); for span in spans.iter() { cx.span_note(*span, "one occurrence here"); } diff --git a/phf_macros/src/util.rs b/phf_macros/src/util.rs index 9b05d238..4caea28d 100644 --- a/phf_macros/src/util.rs +++ b/phf_macros/src/util.rs @@ -68,7 +68,7 @@ impl PhfHash for Key { pub struct Entry { pub key_contents: Key, pub key: P, - pub value: P + pub value: P, } impl PhfHash for Entry { @@ -77,17 +77,24 @@ impl PhfHash for Entry { } } -pub fn create_map(cx: &mut ExtCtxt, sp: Span, entries: Vec, state: HashState) - -> Box { - let disps = state.disps.iter().map(|&(d1, d2)| { - quote_expr!(&*cx, ($d1, $d2)) - }).collect(); +pub fn create_map(cx: &mut ExtCtxt, + sp: Span, + entries: Vec, + state: HashState) + -> Box { + let disps = state.disps + .iter() + .map(|&(d1, d2)| quote_expr!(&*cx, ($d1, $d2))) + .collect(); let disps = cx.expr_vec(sp, disps); - let entries = state.map.iter().map(|&idx| { - let &Entry { ref key, ref value, .. } = &entries[idx]; - quote_expr!(&*cx, ($key, $value)) - }).collect(); + let entries = state.map + .iter() + .map(|&idx| { + let &Entry { ref key, ref value, .. } = &entries[idx]; + quote_expr!(&*cx, ($key, $value)) + }) + .collect(); let entries = cx.expr_vec(sp, entries); let key = state.key; @@ -98,25 +105,34 @@ pub fn create_map(cx: &mut ExtCtxt, sp: Span, entries: Vec, state: HashSt })) } -pub fn create_set(cx: &mut ExtCtxt, sp: Span, entries: Vec, state: HashState) - -> Box { +pub fn create_set(cx: &mut ExtCtxt, + sp: Span, + entries: Vec, + state: HashState) + -> Box { let map = create_map(cx, sp, entries, state).make_expr().unwrap(); MacEager::expr(quote_expr!(cx, ::phf::Set { map: $map })) } -pub fn create_ordered_map(cx: &mut ExtCtxt, sp: Span, entries: Vec, state: HashState) - -> Box { - let disps = state.disps.iter().map(|&(d1, d2)| { - quote_expr!(&*cx, ($d1, $d2)) - }).collect(); +pub fn create_ordered_map(cx: &mut ExtCtxt, + sp: Span, + entries: Vec, + state: HashState) + -> Box { + let disps = state.disps + .iter() + .map(|&(d1, d2)| quote_expr!(&*cx, ($d1, $d2))) + .collect(); let disps = cx.expr_vec(sp, disps); let idxs = state.map.iter().map(|&idx| quote_expr!(&*cx, $idx)).collect(); let idxs = cx.expr_vec(sp, idxs); - let entries = entries.iter().map(|&Entry { ref key, ref value, .. }| { - quote_expr!(&*cx, ($key, $value)) - }).collect(); + let entries = entries.iter() + .map(|&Entry { ref key, ref value, .. }| { + quote_expr!(&*cx, ($key, $value)) + }) + .collect(); let entries = cx.expr_vec(sp, entries); let key = state.key; @@ -128,8 +144,11 @@ pub fn create_ordered_map(cx: &mut ExtCtxt, sp: Span, entries: Vec, state })) } -pub fn create_ordered_set(cx: &mut ExtCtxt, sp: Span, entries: Vec, state: HashState) - -> Box { +pub fn create_ordered_set(cx: &mut ExtCtxt, + sp: Span, + entries: Vec, + state: HashState) + -> Box { let map = create_ordered_map(cx, sp, entries, state).make_expr().unwrap(); MacEager::expr(quote_expr!(cx, ::phf::OrderedSet { map: $map })) } diff --git a/phf_shared/src/lib.rs b/phf_shared/src/lib.rs index 98f33c6d..d755e07e 100644 --- a/phf_shared/src/lib.rs +++ b/phf_shared/src/lib.rs @@ -51,7 +51,9 @@ pub trait PhfHash { fn phf_hash(&self, state: &mut H); /// Feeds a slice of this type into the state provided. - fn phf_hash_slice(data: &[Self], state: &mut H) where Self: Sized { + fn phf_hash_slice(data: &[Self], state: &mut H) + where Self: Sized + { for piece in data { piece.phf_hash(state); }