/// A builder for the `phf::Map` type. pubstruct Map<K> {
keys: Vec<K>,
values: Vec<String>,
path: String,
}
impl<K: Hash + PhfHash + Eq + FmtConst> Map<K> { /// Creates a new `phf::Map` builder. pubfn new() -> Map<K> { // FIXME rust#27438 // // On Windows/MSVC there are major problems with the handling of dllimport. // Here, because downstream build scripts only invoke generics from phf_codegen, // 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() {}
noop_fix_for_27438();
/// Set the path to the `phf` crate from the global namespace pubfn phf_path(&mutself, path: &str) -> &mut Map<K> { self.path = path.to_owned(); self
}
/// Adds an entry to the builder. /// /// `value` will be written exactly as provided in the constructed source. pubfn entry(&mutself, key: K, value: &str) -> &mut Map<K> { self.keys.push(key); self.values.push(value.to_owned()); self
}
/// Calculate the hash parameters and return a struct implementing /// [`Display`](::std::fmt::Display) which will print the constructed `phf::Map`. /// /// # Panics /// /// Panics if there are any duplicate keys. pubfn build(&self) -> DisplayMap<'_, K> { letmut set = HashSet::new(); for key in &self.keys { if !set.insert(key) {
panic!("duplicate key `{}`", Delegate(key));
}
}
let state = phf_generator::generate_hash(&self.keys);
// write map displacements for &(d1, d2) in &self.state.disps {
write!(
f, "
({}, {}),",
d1, d2
)?;
}
write!(
f, "
],
entries: &[",
)?;
// write map entries for &idx in &self.state.map {
write!(
f, "
({}, {}),",
Delegate(&self.keys[idx]),
&self.values[idx]
)?;
}
write!(
f, "
],
}}"
)
}
}
/// A builder for the `phf::Set` type. pubstruct Set<T> {
map: Map<T>,
}
impl<T: Hash + PhfHash + Eq + FmtConst> Set<T> { /// Constructs a new `phf::Set` builder. pubfn new() -> Set<T> {
Set { map: Map::new() }
}
/// Set the path to the `phf` crate from the global namespace pubfn phf_path(&mutself, path: &str) -> &mut Set<T> { self.map.phf_path(path); self
}
/// Adds an entry to the builder. pubfn entry(&mutself, entry: T) -> &mut Set<T> { self.map.entry(entry, "()"); self
}
/// Calculate the hash parameters and return a struct implementing /// [`Display`](::std::fmt::Display) which will print the constructed `phf::Set`. /// /// # Panics /// /// Panics if there are any duplicate keys. pubfn build(&self) -> DisplaySet<'_, T> {
DisplaySet {
inner: self.map.build(),
}
}
}
/// An adapter for printing a [`Set`](Set). pubstruct DisplaySet<'a, T> {
inner: DisplayMap<'a, T>,
}
/// Set the path to the `phf` crate from the global namespace pubfn phf_path(&mutself, path: &str) -> &mut OrderedMap<K> { self.path = path.to_owned(); self
}
/// Adds an entry to the builder. /// /// `value` will be written exactly as provided in the constructed source. pubfn entry(&mutself, key: K, value: &str) -> &mut OrderedMap<K> { self.keys.push(key); self.values.push(value.to_owned()); self
}
/// Calculate the hash parameters and return a struct implementing /// [`Display`](::std::fmt::Display) which will print the constructed /// `phf::OrderedMap`. /// /// # Panics /// /// Panics if there are any duplicate keys. pubfn build(&self) -> DisplayOrderedMap<'_, K> { letmut set = HashSet::new(); for key in &self.keys { if !set.insert(key) {
panic!("duplicate key `{}`", Delegate(key));
}
}
let state = phf_generator::generate_hash(&self.keys);
/// Set the path to the `phf` crate from the global namespace pubfn phf_path(&mutself, path: &str) -> &mut OrderedSet<T> { self.map.phf_path(path); self
}
/// Adds an entry to the builder. pubfn entry(&mutself, entry: T) -> &mut OrderedSet<T> { self.map.entry(entry, "()"); self
}
/// Calculate the hash parameters and return a struct implementing /// [`Display`](::std::fmt::Display) which will print the constructed /// `phf::OrderedSet`. /// /// # Panics /// /// Panics if there are any duplicate keys. pubfn build(&self) -> DisplayOrderedSet<'_, T> {
DisplayOrderedSet {
inner: self.map.build(),
}
}
}
/// An adapter for printing a [`OrderedSet`](OrderedSet). pubstruct DisplayOrderedSet<'a, T> {
inner: DisplayOrderedMap<'a, T>,
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.