Skip to main content

crabka_protocol/
api_key.rs

1// Clippy lints that fire on generated code patterns are suppressed here so
2// that regenerating the file does not require manual allow annotations.
3#![allow(
4    clippy::elidable_lifetime_names,
5    clippy::must_use_candidate,
6    clippy::unnecessary_wraps,
7    clippy::cast_sign_loss,
8    clippy::cast_possible_truncation,
9    clippy::cast_possible_wrap,
10    clippy::default_trait_access,
11    clippy::derivable_impls,
12    clippy::collapsible_if,
13    clippy::new_without_default,
14    clippy::unreadable_literal,
15    clippy::redundant_closure_for_method_calls,
16    clippy::nonminimal_bool,
17    clippy::bool_comparison,
18    clippy::map_unwrap_or,
19    clippy::option_as_ref_deref,
20    clippy::manual_range_contains
21)]
22
23include!(concat!(env!("CARGO_MANIFEST_DIR"), "/generated/api_key.rs"));
24
25#[cfg(test)]
26mod tests {
27    use super::*;
28    use assert2::assert;
29
30    #[test]
31    fn all_keys_unique() {
32        let mut seen = std::collections::HashSet::new();
33        for k in ApiKey::ALL {
34            assert!(seen.insert(*k as i16), "duplicate: {k:?}");
35        }
36    }
37
38    #[test]
39    fn from_i16_round_trip() {
40        for k in ApiKey::ALL {
41            assert!(ApiKey::from_i16(*k as i16) == Some(*k));
42        }
43        assert!(ApiKey::from_i16(-1) == None);
44        assert!(ApiKey::from_i16(9999) == None);
45    }
46}