luwen_core/
lib.rs

1// SPDX-FileCopyrightText: © 2023 Tenstorrent Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use std::fmt;
5use std::str::FromStr;
6
7#[derive(Clone, Hash, Copy, Debug, PartialEq, Eq)]
8pub enum Arch {
9    Grayskull,
10    Wormhole,
11    Blackhole,
12}
13
14impl Default for Arch {
15    fn default() -> Self {
16        Self::Grayskull
17    }
18}
19
20impl Arch {
21    pub fn is_wormhole(&self) -> bool {
22        matches!(self, Arch::Wormhole)
23    }
24
25    pub fn is_grayskull(&self) -> bool {
26        matches!(self, Arch::Grayskull)
27    }
28
29    pub fn is_blackhole(&self) -> bool {
30        matches!(self, Arch::Blackhole)
31    }
32}
33
34impl FromStr for Arch {
35    type Err = String;
36
37    fn from_str(s: &str) -> Result<Self, Self::Err> {
38        match s {
39            "grayskull" => Ok(Arch::Grayskull),
40            "wormhole" => Ok(Arch::Wormhole),
41            "blackhole" => Ok(Arch::Blackhole),
42            err => Err(err.to_string()),
43        }
44    }
45}
46
47impl fmt::Display for Arch {
48    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
49        match self {
50            Arch::Grayskull => write!(f, "Grayskull"),
51            Arch::Wormhole => write!(f, "Wormhole"),
52            Arch::Blackhole => write!(f, "Blackhole"),
53        }
54    }
55}