@@ -11,7 +11,7 @@ impl AllergenInfo {
11
11
// use reduce to or the allergen flags
12
12
let allergen_flags = elements
13
13
. filter_map ( |element| element. value ( ) . attr ( "src" ) )
14
- . map ( |img_url| Self :: img_url_to_allergen ( img_url ) ) ;
14
+ . map ( Self :: img_url_to_allergen) ;
15
15
// if there is an error, return the error via a for loop
16
16
let mut acc = AllergenFlags :: empty ( ) ;
17
17
for allergen_flag in allergen_flags {
@@ -72,31 +72,27 @@ impl AllergenInfo {
72
72
bitflags ! {
73
73
#[ derive( Debug , PartialEq , Eq ) ]
74
74
pub struct AllergenFlags : u16 {
75
- const Egg = 0b0000000000000001 ;
76
- const Fish = 0b0000000000000010 ;
77
- const GlutenFriendly = 0b0000000000000100 ;
78
- const Milk = 0b000000000001000 ;
79
- const Peanut = 0b0000000000010000 ;
80
- const Soy = 0b0000000000100000 ;
81
- const TreeNut = 0b0000000001000000 ;
82
- const Alcohol = 0b0000000010000000 ;
83
- const Vegan = 0b0000000100000000 ;
84
- const Vegetarian = 0b0000001000000000 ;
85
- const Pork = 0b0000010000000000 ;
86
- const Beef = 0b0000100000000000 ;
87
- const Halal = 0b0001000000000000 ;
88
- const Shellfish = 0b0010000000000000 ;
89
- const Sesame = 0b0100000000000000 ;
75
+ const Egg = 1 ;
76
+ const Fish = 1 << 1 ;
77
+ const GlutenFriendly = 1 << 2 ;
78
+ const Milk = 1 << 3 ;
79
+ const Peanut = 1 << 4 ;
80
+ const Soy = 1 << 5 ;
81
+ const TreeNut = 1 << 6 ;
82
+ const Alcohol = 1 << 7 ;
83
+ const Vegan = 1 << 8 ;
84
+ const Vegetarian = 1 << 9 ;
85
+ const Pork = 1 << 10 ;
86
+ const Beef = 1 << 11 ;
87
+ const Halal = 1 << 12 ;
88
+ const Shellfish = 1 << 13 ;
89
+ const Sesame = 1 << 14 ;
90
90
}
91
91
}
92
92
93
93
#[ cfg( test) ]
94
94
95
95
mod tests {
96
- use std:: sync:: OnceLock ;
97
-
98
- use scraper:: Selector ;
99
-
100
96
use crate :: static_selector;
101
97
102
98
use super :: * ;
@@ -170,7 +166,6 @@ mod tests {
170
166
// source: https://nutrition.sa.ucsc.edu/allergenfilter.aspx?strcurlocationnum=40
171
167
172
168
let doc = scraper:: Html :: parse_document ( HTML ) ;
173
- static SELECTOR : OnceLock < Selector > = OnceLock :: new ( ) ;
174
169
static_selector ! ( DATE_SELECTOR <- "img" ) ;
175
170
let mut all_allergen_flags = AllergenFlags :: empty ( ) ;
176
171
for element in doc. select ( & DATE_SELECTOR ) {
@@ -183,6 +178,6 @@ mod tests {
183
178
all_allergen_flags |= allergen_flags;
184
179
}
185
180
// ensure that all the allergen flags are picked up properly
186
- assert ! ( all_allergen_flags. is_all( ) )
181
+ assert ! ( all_allergen_flags. is_all( ) ) ;
187
182
}
188
183
}
0 commit comments