autopush_common/db/
routing.rs

1// Rust 1.89.0 flags `StorageType` as unused even with `bigtable` set as a default feature.
2#[allow(dead_code)]
3#[derive(Clone, Eq, PartialEq, Debug)]
4pub(crate) enum StorageType {
5    #[cfg(feature = "bigtable")]
6    BigTable,
7    #[cfg(feature = "postgres")]
8    Postgres,
9    #[cfg(feature = "redis")]
10    Redis,
11    None,
12}
13
14impl Default for StorageType {
15    // It's OK clippy, we're setting a default.
16    #[allow(unreachable_code)]
17    fn default() -> StorageType {
18        #[cfg(feature = "bigtable")]
19        return StorageType::BigTable;
20        #[cfg(feature = "redis")]
21        return StorageType::Redis;
22        #[cfg(feature = "postgres")]
23        return StorageType::Postgres;
24        #[cfg(not(any(feature = "bigtable", feature = "redis", feature = "postgres")))]
25        return StorageType::None;
26    }
27}
28
29impl From<&str> for StorageType {
30    fn from(str: &str) -> StorageType {
31        match str.to_lowercase().as_str() {
32            #[cfg(feature = "bigtable")]
33            "bigtable" => StorageType::BigTable,
34            #[cfg(feature = "postgres")]
35            "postgres" => StorageType::Postgres,
36            #[cfg(feature = "redis")]
37            "redis" => StorageType::Redis,
38            _ => {
39                warn!("Using default StorageType for {str}");
40                StorageType::default()
41            }
42        }
43    }
44}