mirror of
https://github.com/crate-ci/typos.git
synced 2025-01-11 09:11:39 -05:00
refactor(dictgen): Make room for different maps
This commit is contained in:
parent
d4767767b2
commit
92c9aa17f4
1 changed files with 14 additions and 10 deletions
|
@ -19,6 +19,19 @@ impl MapGen<'_> {
|
||||||
|
|
||||||
let mut smallest = usize::MAX;
|
let mut smallest = usize::MAX;
|
||||||
let mut largest = usize::MIN;
|
let mut largest = usize::MIN;
|
||||||
|
for (key, _) in data.iter() {
|
||||||
|
smallest = std::cmp::min(smallest, key.len());
|
||||||
|
largest = std::cmp::max(largest, key.len());
|
||||||
|
}
|
||||||
|
if largest == 0 {
|
||||||
|
smallest = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
writeln!(
|
||||||
|
file,
|
||||||
|
"pub static {name}: dictgen::Map<{key_type}, {value_type}> = dictgen::Map {{"
|
||||||
|
)?;
|
||||||
|
|
||||||
let mut builder = phf_codegen::Map::new();
|
let mut builder = phf_codegen::Map::new();
|
||||||
let data = data
|
let data = data
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -34,20 +47,11 @@ impl MapGen<'_> {
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
for (key, value) in data.iter() {
|
for (key, value) in data.iter() {
|
||||||
smallest = std::cmp::min(smallest, key.len());
|
|
||||||
largest = std::cmp::max(largest, key.len());
|
|
||||||
builder.entry(key, value.as_str());
|
builder.entry(key, value.as_str());
|
||||||
}
|
}
|
||||||
let builder = builder.build();
|
let builder = builder.build();
|
||||||
if largest == 0 {
|
|
||||||
smallest = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
writeln!(
|
|
||||||
file,
|
|
||||||
"pub static {name}: dictgen::Map<{key_type}, {value_type}> = dictgen::Map {{"
|
|
||||||
)?;
|
|
||||||
writeln!(file, " map: {builder},")?;
|
writeln!(file, " map: {builder},")?;
|
||||||
|
|
||||||
writeln!(file, " range: {smallest}..={largest},")?;
|
writeln!(file, " range: {smallest}..={largest},")?;
|
||||||
writeln!(file, "}};")?;
|
writeln!(file, "}};")?;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue