use crate::grammar::Encoding;
#[derive(Clone, Debug)]
pub struct SupportedEncodings(Vec<Encoding>);
impl SupportedEncodings {
pub fn new(mut encodings: Vec<Encoding>) -> Self {
encodings.sort();
encodings.dedup();
SupportedEncodings(encodings)
}
pub fn supports(&self, encoding: Encoding) -> bool {
self.0.contains(&encoding)
}
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
pub(crate) fn disable(&mut self, encoding: Encoding) {
self.0.retain(|&e| e != encoding);
}
pub(crate) fn intersect_with(&mut self, other: &SupportedEncodings) {
self.0.retain(|encoding| other.0.contains(encoding));
}
pub(crate) fn dummy() -> Self {
SupportedEncodings(vec![Encoding::Slice1, Encoding::Slice2])
}
}
impl<I: std::slice::SliceIndex<[Encoding]>> std::ops::Index<I> for SupportedEncodings {
type Output = I::Output;
fn index(&self, index: I) -> &Self::Output {
&self.0[index]
}
}