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
// Copyright (c) 2021 Xu Shaohua <shaohua@biofan.org>. All rights reserved.
// Use of this source is governed by Apache-2.0 License that can be found
// in the LICENSE file.

use std::str::FromStr;

use crate::error::{Error, ErrorKind};

#[derive(Debug)]
pub enum Arch {
    AArch64,
    Arm,
    X86,
    X86_64,
}

impl FromStr for Arch {
    type Err = Error;

    fn from_str(input: &str) -> Result<Self, Self::Err> {
        match input {
            "arm64" => Ok(Arch::AArch64),
            "aarch64" => Ok(Arch::AArch64),

            "x86" => Ok(Arch::X86),
            "i386" => Ok(Arch::X86),
            "i686" => Ok(Arch::X86),

            "x86_64" => Ok(Arch::X86_64),
            "amd64" => Ok(Arch::X86_64),
            _ => Err(Error::from_string(
                ErrorKind::InvalidArchError,
                format!("Invalid arch {}", input),
            )),
        }
    }
}