use fmt::Formatter;
use std::collections::BTreeSet;
use std::fmt;
#[derive(Eq, PartialEq, PartialOrd, Ord, Hash)]
pub struct ParameterAttributes {
attrs: BTreeSet<ParameterAttribute>,
}
impl Default for ParameterAttributes {
fn default() -> Self {
Self {
attrs: BTreeSet::new(),
}
}
}
impl ParameterAttributes {
pub fn add_attr(&mut self, attr: ParameterAttribute) {
self.attrs.insert(attr);
}
}
impl fmt::Display for ParameterAttributes {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
let fmt_string = self
.attrs
.iter()
.map(|attr| attr.to_string())
.collect::<Vec<String>>()
.join(", ");
write!(f, "{}", fmt_string)
}
}
#[derive(Eq, PartialEq, PartialOrd, Ord, Hash)]
pub enum ParameterAttribute {
ZEROEXT,
SIGNEXT,
}
impl fmt::Display for ParameterAttribute {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
let attr_string = match self {
Self::ZEROEXT => "zeroext",
Self::SIGNEXT => "signext",
};
write!(f, "{}", attr_string)
}
}