1use std::convert::TryFrom;
2use crate::Error;
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
5#[derive(serde::Deserialize, serde::Serialize)]
6pub enum Format {
7 Raw,
8 PE,
9 ELF,
10 TE,
11 MachO,
12 Other,
13}
14
15impl Format {
16 pub fn is_elf(&self) -> bool {
17 *self == Self::ELF
18 }
19
20 pub fn is_pe(&self) -> bool {
21 *self == Self::PE
22 }
23
24 pub fn is_raw(&self) -> bool {
25 *self == Self::Raw
26 }
27
28 pub fn is_macho(&self) -> bool {
29 *self == Self::MachO
30 }
31
32 pub fn is_te(&self) -> bool {
33 *self == Self::TE
34 }
35
36 pub fn is_other(&self) -> bool {
37 *self == Self::Other
38 }
39}
40
41impl TryFrom<&str> for Format {
42 type Error = Error;
43
44 fn try_from(value: &str) -> Result<Self, Error> {
45 match value {
46 "Raw" => Ok(Self::Raw),
47 "PE" => Ok(Self::PE),
48 "ELF" => Ok(Self::ELF),
49 "Mach-O" => Ok(Self::MachO),
50 "TE" => Ok(Self::TE),
51 "Other" => Ok(Self::Other),
52 _ => Err(Error::UnsupportedFormat(value.to_string())),
53 }
54 }
55}
56
57impl Into<&'static str> for Format {
58 fn into(self) -> &'static str {
59 match self {
60 Self::Raw => "Raw",
61 Self::PE => "PE",
62 Self::ELF => "ELF",
63 Self::MachO => "Mach-O",
64 Self::Other => "Other",
65 Self::TE => "TE",
66 }
67 }
68}