This code:
let mut small_cousins = vec![];
if end_num < 49 {
for c_hi in [11, 17, 23, 41, 47 ].iter().enumerate() {
if start_num <= c_hi && c_hi <= end_num { small_cousins.push(c_hi); }
if small_cousins.is_empty() {
cousinscnt = 0; last_cousin = 0;
}
else {
cousinscnt = small_cousins.len(); last_cousin = small_cousins.iter().max(); };
}
}
produces the following errors, and I've tried everything, and finally have to ask why.
And I'm sure this snippet can be written simpler.
Help will be appreciated.
➜ cousinprimes_ssoz RUSTFLAGS="-C opt-level=3 -C debuginfo=0 -C target-cpu=native" cargo build --release
Compiling cousinprimes_ssoz v1.0.0 (/home/jzakiya/rust-projects/cousinprimes_ssoz)
error[E0308]: mismatched types
--> src/main.rs:317:23
|
317 | if start_num <= c_hi && c_hi <= end_num { small_cousins.push(c_hi); }
| ^^^^ expected `usize`, found tuple
|
= note: expected type `usize`
found tuple `(usize, &{integer})`
error[E0308]: mismatched types
--> src/main.rs:317:39
|
317 | if start_num <= c_hi && c_hi <= end_num { small_cousins.push(c_hi); }
| ^^^^^^^ expected tuple, found `usize`
|
= note: expected tuple `(usize, &{integer})`
found type `usize`
error[E0308]: mismatched types
--> src/main.rs:321:55
|
321 | cousinscnt = small_cousins.len(); last_cousin = small_cousins.iter().max(); };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found enum `Option`
|
= note: expected type `usize`
found enum `Option<&(usize, &{integer})>`
For more information about this error, try `rustc --explain E0308`.
error: could not compile `cousinprimes_ssoz` due to 3 previous errors
➜ cousinprimes_ssoz