From: Arik Sosman Date: Thu, 22 Jun 2023 21:14:02 +0000 (-0700) Subject: Reference-rhs bitwise operations for features. X-Git-Tag: v0.0.116-alpha1~4^2~5 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=bf2218260ec3934efb13f953c5a8141c6978be0a;p=rust-lightning Reference-rhs bitwise operations for features. --- diff --git a/lightning/src/ln/features.rs b/lightning/src/ln/features.rs index 400888ff9..3e3484e73 100644 --- a/lightning/src/ln/features.rs +++ b/lightning/src/ln/features.rs @@ -77,6 +77,7 @@ use crate::{io, io_extras}; use crate::prelude::*; use core::{cmp, fmt}; +use core::borrow::Borrow; use core::hash::{Hash, Hasher}; use core::marker::PhantomData; @@ -431,15 +432,21 @@ pub struct Features { mark: PhantomData, } +impl> core::ops::BitOrAssign for Features { + fn bitor_assign(&mut self, rhs: Rhs) { + let total_feature_len = cmp::max(self.flags.len(), rhs.borrow().flags.len()); + self.flags.resize(total_feature_len, 0u8); + for (byte, rhs_byte) in self.flags.iter_mut().zip(rhs.borrow().flags.iter()) { + *byte |= *rhs_byte; + } + } +} + impl core::ops::BitOr for Features { type Output = Self; fn bitor(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 |= o; self } }