Enable all feature sets to OR with another set of the same type

This commit is contained in:
Valentine Wallace 2022-09-09 11:54:22 -04:00
parent 3fb3218b6c
commit fe8b4c7836
No known key found for this signature in database
GPG key ID: FD3E106A2CE099B4

View file

@ -470,6 +470,17 @@ pub struct Features<T: sealed::Context> {
mark: PhantomData<T>,
}
impl <T: sealed::Context> Features<T> {
pub(crate) fn or(mut self, o: Self) -> Self {
let total_feature_len = cmp::max(self.flags.len(), o.flags.len());
self.flags.resize(total_feature_len, 0u8);
for (byte, o_byte) in self.flags.iter_mut().zip(o.flags.iter()) {
*byte |= *o_byte;
}
self
}
}
impl<T: sealed::Context> Clone for Features<T> {
fn clone(&self) -> Self {
Self {
@ -532,16 +543,6 @@ impl InitFeatures {
Ok(())
}
/// or's another InitFeatures into this one.
pub(crate) fn or(mut self, o: InitFeatures) -> InitFeatures {
let total_feature_len = cmp::max(self.flags.len(), o.flags.len());
self.flags.resize(total_feature_len, 0u8);
for (byte, o_byte) in self.flags.iter_mut().zip(o.flags.iter()) {
*byte |= *o_byte;
}
self
}
/// Converts `InitFeatures` to `Features<C>`. Only known `InitFeatures` relevant to context `C`
/// are included in the result.
pub(crate) fn to_context<C: sealed::Context>(&self) -> Features<C> {