pelf 0.1.5

A library for parsing/generating/analyzing ELF
Documentation
use crate::Elf64Half;

/// indicates the target machine is none.
pub const ELF_MACHINE_NONE: Elf64Half = 0;

/// indicates the target machine is AMD x86_64 architecture.
pub const ELF_MACHINE_X86_64: Elf64Half = 62;

/// the target architecture of an ELF file.
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum ElfMachine {
    /// no machine
    None,
    /// AMD x86_64 architecture
    X86_64,
    /// custom value
    Any(Elf64Half),
}

impl std::fmt::Display for ElfMachine {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        let s = match self {
            Self::None => "None".to_string(),
            Self::X86_64 => "Advanced Micro Devices X86-64".to_string(),
            Self::Any(v) => format!("Unknown!({})", v),
        };
        write!(f, "{}", s)
    }
}

impl From<Elf64Half> for ElfMachine {
    fn from(value: Elf64Half) -> Self {
        match value {
            ELF_MACHINE_NONE => Self::None,
            ELF_MACHINE_X86_64 => Self::X86_64,
            _ => Self::Any(value),
        }
    }
}

impl Default for ElfMachine {
    fn default() -> Self {
        Self::None
    }
}