1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//! [`BatteryChemistry`] — the cell chemistry a battery declares.
use serde::{Deserialize, Serialize};
/// Battery electrochemical chemistry with `#[serde(other)]` fallback for future types.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub enum BatteryChemistry {
#[serde(rename = "LFP")]
Lfp,
#[serde(rename = "NMC")]
Nmc,
#[serde(rename = "NCA")]
Nca,
#[serde(rename = "LCO")]
Lco,
#[serde(rename = "NiMH")]
NiMh,
#[serde(rename = "NiCd")]
NiCd,
#[serde(rename = "lead-acid")]
LeadAcid,
#[serde(rename = "solid-state")]
SolidState,
/// Absorbs unknown chemistry codes on deserialization (forward compatibility).
#[serde(other)]
Other,
}
impl BatteryChemistry {
/// The serde wire tag for this chemistry code, e.g. `"LFP"`, `"lead-acid"`.
/// Equivalent to `serde_json::to_value(self)` but without the allocation
/// and `Value` round trip.
pub const fn wire_str(&self) -> &'static str {
match self {
Self::Lfp => "LFP",
Self::Nmc => "NMC",
Self::Nca => "NCA",
Self::Lco => "LCO",
Self::NiMh => "NiMH",
Self::NiCd => "NiCd",
Self::LeadAcid => "lead-acid",
Self::SolidState => "solid-state",
Self::Other => "Other",
}
}
}