1use serde::{Deserialize, Serialize};
2use strum::{Display, EnumString};
3
4#[derive(
35 Clone,
36 Copy,
37 Debug,
38 Deserialize,
39 Display,
40 EnumString,
41 Eq,
42 Hash,
43 Ord,
44 PartialEq,
45 PartialOrd,
46 Serialize,
47)]
48#[non_exhaustive]
49#[strum(serialize_all = "lowercase")]
50#[serde(rename_all = "lowercase")]
51pub enum Architecture {
52 Aarch64,
54 Any,
56 Arm,
58 Armv6h,
60 Armv7h,
62 I386,
64 I486,
66 I686,
68 Pentium4,
70 Riscv32,
72 Riscv64,
74 X86_64,
76 #[strum(to_string = "x86_64_v2")]
78 X86_64V2,
79 #[strum(to_string = "x86_64_v3")]
81 X86_64V3,
82 #[strum(to_string = "x86_64_v4")]
84 X86_64V4,
85}
86
87#[derive(
118 Clone, Copy, Debug, Deserialize, Display, EnumString, Eq, Ord, PartialEq, PartialOrd, Serialize,
119)]
120#[non_exhaustive]
121#[strum(serialize_all = "lowercase")]
122pub enum ElfArchitectureFormat {
123 #[strum(to_string = "32")]
125 Bit32 = 32,
126 #[strum(to_string = "64")]
128 Bit64 = 64,
129}
130
131#[cfg(test)]
132mod tests {
133 use std::str::FromStr;
134
135 use rstest::rstest;
136 use strum::ParseError;
137
138 use super::*;
139
140 #[rstest]
141 #[case("aarch64", Ok(Architecture::Aarch64))]
142 #[case("any", Ok(Architecture::Any))]
143 #[case("arm", Ok(Architecture::Arm))]
144 #[case("armv6h", Ok(Architecture::Armv6h))]
145 #[case("armv7h", Ok(Architecture::Armv7h))]
146 #[case("i386", Ok(Architecture::I386))]
147 #[case("i486", Ok(Architecture::I486))]
148 #[case("i686", Ok(Architecture::I686))]
149 #[case("pentium4", Ok(Architecture::Pentium4))]
150 #[case("riscv32", Ok(Architecture::Riscv32))]
151 #[case("riscv64", Ok(Architecture::Riscv64))]
152 #[case("x86_64", Ok(Architecture::X86_64))]
153 #[case("x86_64_v2", Ok(Architecture::X86_64V2))]
154 #[case("x86_64_v3", Ok(Architecture::X86_64V3))]
155 #[case("x86_64_v4", Ok(Architecture::X86_64V4))]
156 #[case("foo", Err(ParseError::VariantNotFound))]
157 fn architecture_from_string(#[case] s: &str, #[case] arch: Result<Architecture, ParseError>) {
158 assert_eq!(Architecture::from_str(s), arch);
159 }
160
161 #[rstest]
162 #[case(Architecture::Aarch64, "aarch64")]
163 #[case(Architecture::Any, "any")]
164 #[case(Architecture::Arm, "arm")]
165 #[case(Architecture::Armv6h, "armv6h")]
166 #[case(Architecture::Armv7h, "armv7h")]
167 #[case(Architecture::I386, "i386")]
168 #[case(Architecture::I486, "i486")]
169 #[case(Architecture::I686, "i686")]
170 #[case(Architecture::Pentium4, "pentium4")]
171 #[case(Architecture::Riscv32, "riscv32")]
172 #[case(Architecture::Riscv64, "riscv64")]
173 #[case(Architecture::X86_64, "x86_64")]
174 #[case(Architecture::X86_64V2, "x86_64_v2")]
175 #[case(Architecture::X86_64V3, "x86_64_v3")]
176 #[case(Architecture::X86_64V4, "x86_64_v4")]
177 fn architecture_format_string(#[case] arch: Architecture, #[case] arch_str: &str) {
178 assert_eq!(arch_str, format!("{}", arch));
179 }
180
181 #[rstest]
182 #[case("32", Ok(ElfArchitectureFormat::Bit32))]
183 #[case("64", Ok(ElfArchitectureFormat::Bit64))]
184 #[case("foo", Err(ParseError::VariantNotFound))]
185 fn elf_architecture_format_from_string(
186 #[case] s: &str,
187 #[case] arch: Result<ElfArchitectureFormat, ParseError>,
188 ) {
189 assert_eq!(ElfArchitectureFormat::from_str(s), arch);
190 }
191
192 #[rstest]
193 #[case(ElfArchitectureFormat::Bit32, "32")]
194 #[case(ElfArchitectureFormat::Bit64, "64")]
195 fn elf_architecture_format_display(
196 #[case] arch: ElfArchitectureFormat,
197 #[case] arch_str: &str,
198 ) {
199 assert_eq!(arch_str, format!("{}", arch));
200 }
201}