Skip to content

Commit 137cfea

Browse files
Merge pull request #3241 from TheBlueMatt/2024-08-ret-slice-not-ref-vec
Return slices, rather than `Vec` references, in addresses
2 parents 33e6995 + b3aed9a commit 137cfea

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

lightning-rapid-gossip-sync/src/processing.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ where
178178
synthetic_node_announcement.features = info.features().clone();
179179
synthetic_node_announcement.rgb = info.rgb().clone();
180180
synthetic_node_announcement.alias = info.alias().clone();
181-
synthetic_node_announcement.addresses = info.addresses().clone();
181+
synthetic_node_announcement.addresses = info.addresses().to_vec();
182182
});
183183

184184
if has_address_details {

lightning/src/onion_message/messenger.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ where
595595

596596
match node_details {
597597
Some((features, addresses)) if features.supports_onion_messages() && addresses.len() > 0 => {
598-
let first_node_addresses = Some(addresses.clone());
598+
let first_node_addresses = Some(addresses.to_vec());
599599
Ok(OnionMessagePath {
600600
intermediate_nodes: vec![], destination, first_node_addresses
601601
})

lightning/src/routing/gossip.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,7 @@ impl NodeAnnouncementInfo {
13081308
}
13091309

13101310
/// Internet-level addresses via which one can connect to the node
1311-
pub fn addresses(&self) -> &Vec<SocketAddress> {
1311+
pub fn addresses(&self) -> &[SocketAddress] {
13121312
match self {
13131313
NodeAnnouncementInfo::Relayed(relayed) => {
13141314
&relayed.contents.addresses

lightning/src/util/ser.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -656,10 +656,24 @@ impl Readable for WithoutLength<UntrustedString> {
656656
}
657657
}
658658

659-
impl<'a, T: Writeable> Writeable for WithoutLength<&'a Vec<T>> {
659+
trait AsWriteableSlice {
660+
type Inner: Writeable;
661+
fn as_slice(&self) -> &[Self::Inner];
662+
}
663+
664+
impl<T: Writeable> AsWriteableSlice for &Vec<T> {
665+
type Inner = T;
666+
fn as_slice(&self) -> &[T] { &self }
667+
}
668+
impl<T: Writeable> AsWriteableSlice for &[T] {
669+
type Inner = T;
670+
fn as_slice(&self) -> &[T] { &self }
671+
}
672+
673+
impl<S: AsWriteableSlice> Writeable for WithoutLength<S> {
660674
#[inline]
661675
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
662-
for ref v in self.0.iter() {
676+
for ref v in self.0.as_slice() {
663677
v.write(writer)?;
664678
}
665679
Ok(())

0 commit comments

Comments
 (0)