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
29    #[test]
30    fn all_keys_unique() {
31        let mut seen = std::collections::HashSet::new();
32        for k in ApiKey::ALL {
33            assert!(seen.insert(*k as i16), "duplicate: {k:?}");
34        }
35    }
36
37    #[test]
38    fn from_i16_round_trip() {
39        for k in ApiKey::ALL {
40            assert_eq!(ApiKey::from_i16(*k as i16), Some(*k));
41        }
42        assert_eq!(ApiKey::from_i16(-1), None);
43        assert_eq!(ApiKey::from_i16(9999), None);
44    }
45}