Enable all feature sets to OR with another set of the same type
authorValentine Wallace <vwallace@protonmail.com>
Fri, 9 Sep 2022 15:54:22 +0000 (11:54 -0400)
committerValentine Wallace <vwallace@protonmail.com>
Fri, 9 Sep 2022 16:48:09 +0000 (12:48 -0400)
lightning/src/ln/features.rs

index 91922f1a45f26748f9fdaf8c7ba009a068f6d6b9..a680d0184e7601502763dcdb68824ad97342e545 100644 (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> {