cranelift_assembler_x64_meta/dsl/
features.rs1use core::fmt;
4use std::ops::BitOr;
5
6#[derive(PartialEq)]
17pub struct Features(Vec<Feature>);
18
19impl Features {
20 #[must_use]
21 pub fn is_empty(&self) -> bool {
22 self.0.is_empty()
23 }
24
25 pub fn iter(&self) -> impl Iterator<Item = &Feature> {
26 self.0.iter()
27 }
28}
29
30impl fmt::Display for Features {
31 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
32 write!(
33 f,
34 "{}",
35 self.0
36 .iter()
37 .map(ToString::to_string)
38 .collect::<Vec<_>>()
39 .join(" | ")
40 )
41 }
42}
43
44#[derive(Clone, Copy, PartialEq)]
51#[allow(non_camel_case_types, reason = "makes DSL definitions easier to read")]
52pub enum Feature {
53 _64b,
54 compat,
55}
56
57pub const ALL_FEATURES: &[Feature] = &[Feature::_64b, Feature::compat];
65
66impl fmt::Display for Feature {
67 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
68 match self {
69 Feature::_64b => write!(f, "_64b"),
70 Feature::compat => write!(f, "compat"),
71 }
72 }
73}
74
75impl From<Feature> for Features {
76 fn from(flag: Feature) -> Self {
77 Features(vec![flag])
78 }
79}
80
81impl From<Option<Feature>> for Features {
82 fn from(flag: Option<Feature>) -> Self {
83 Features(flag.into_iter().collect())
84 }
85}
86
87impl BitOr for Feature {
88 type Output = Features;
89 fn bitor(self, rhs: Self) -> Self::Output {
90 Features(vec![self, rhs])
91 }
92}