shell_rs/core/
arch.rs

1// Copyright (c) 2021 Xu Shaohua <shaohua@biofan.org>. All rights reserved.
2// Use of this source is governed by Apache-2.0 License that can be found
3// in the LICENSE file.
4
5use std::str::FromStr;
6
7use crate::error::{Error, ErrorKind};
8
9#[derive(Debug)]
10pub enum Arch {
11    AArch64,
12    Arm,
13    X86,
14    X86_64,
15}
16
17impl FromStr for Arch {
18    type Err = Error;
19
20    fn from_str(input: &str) -> Result<Self, Self::Err> {
21        match input {
22            "arm64" => Ok(Arch::AArch64),
23            "aarch64" => Ok(Arch::AArch64),
24
25            "x86" => Ok(Arch::X86),
26            "i386" => Ok(Arch::X86),
27            "i686" => Ok(Arch::X86),
28
29            "x86_64" => Ok(Arch::X86_64),
30            "amd64" => Ok(Arch::X86_64),
31            _ => Err(Error::from_string(
32                ErrorKind::InvalidArchError,
33                format!("Invalid arch {}", input),
34            )),
35        }
36    }
37}