Skip to content

Commit f275a3c

Browse files
committed
refactor
1 parent ab15157 commit f275a3c

1 file changed

Lines changed: 20 additions & 17 deletions

File tree

‎src/tools/tidy/src/style.rs‎

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,29 +70,32 @@ fn generate_problems<'a>(
7070
consts:&'a[u32],
7171
letter_digit:&'aHashMap<char,char>,
7272
) -> implIterator<Item = u32> + 'a{
73-
consts.into_iter().flat_map(move |const_value| {
74-
letmutproblem =format!("{:X}", const_value);
75-
for(key, value)in letter_digit{
76-
problem = problem.replace(&value.to_string(),&key.to_string());
77-
}
73+
consts.iter().flat_map(move |const_value| {
74+
let problem =
75+
letter_digit.iter().fold(format!("{:X}", const_value), |acc,(key, value)|{
76+
acc.replace(&value.to_string(),&key.to_string())
77+
});
7878
let indexes:Vec<usize> = problem
7979
.chars()
8080
.enumerate()
8181
.filter_map(|(index, c)| if letter_digit.contains_key(&c){Some(index)}else{None})
8282
.collect();
8383
(0..1 << indexes.len()).map(move |i| {
84-
let result = problem
85-
.chars()
86-
.enumerate()
87-
.map(|(index, c)| {
88-
ifletSome(pos) = indexes.iter().position(|&x| x == index){
89-
if(i >> pos)&1 == 1{ letter_digit[&c]}else{ c }
90-
}else{
91-
c
92-
}
93-
})
94-
.collect::<String>();
95-
u32::from_str_radix(&result,0x10).unwrap()
84+
u32::from_str_radix(
85+
&problem
86+
.chars()
87+
.enumerate()
88+
.map(|(index, c)| {
89+
ifletSome(pos) = indexes.iter().position(|&x| x == index){
90+
if(i >> pos)&1 == 1{ letter_digit[&c]}else{ c }
91+
}else{
92+
c
93+
}
94+
})
95+
.collect::<String>(),
96+
0x10,
97+
)
98+
.unwrap()
9699
})
97100
})
98101
}

0 commit comments

Comments
 (0)