wasm_pack/install/
arch.rs

1use anyhow::{bail, Result};
2use std::fmt;
3
4use crate::target;
5
6/// An enum representing supported architectures
7#[derive(Clone, PartialEq, Eq)]
8pub enum Arch {
9    /// x86 64-bit
10    X86_64,
11    /// x86 32-bit
12    X86,
13    /// ARM 64-bit
14    AArch64,
15}
16
17impl Arch {
18    /// Gets the current architecture
19    pub fn get() -> Result<Self> {
20        if target::x86_64 {
21            Ok(Arch::X86_64)
22        } else if target::x86 {
23            Ok(Arch::X86)
24        } else if target::aarch64 {
25            Ok(Arch::AArch64)
26        } else {
27            bail!("Unrecognized target!")
28        }
29    }
30}
31
32impl fmt::Display for Arch {
33    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
34        let s = match self {
35            Arch::X86_64 => "x86-64",
36            Arch::X86 => "x86",
37            Arch::AArch64 => "aarch64",
38        };
39        write!(f, "{}", s)
40    }
41}