Skip to content

Return slices, rather than Vec references, in addresses #3241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lightning-rapid-gossip-sync/src/processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ where
synthetic_node_announcement.features = info.features().clone();
synthetic_node_announcement.rgb = info.rgb().clone();
synthetic_node_announcement.alias = info.alias().clone();
synthetic_node_announcement.addresses = info.addresses().clone();
synthetic_node_announcement.addresses = info.addresses().to_vec();
});

if has_address_details {
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/onion_message/messenger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ where

match node_details {
Some((features, addresses)) if features.supports_onion_messages() && addresses.len() > 0 => {
let first_node_addresses = Some(addresses.clone());
let first_node_addresses = Some(addresses.to_vec());
Ok(OnionMessagePath {
intermediate_nodes: vec![], destination, first_node_addresses
})
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/routing/gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1308,7 +1308,7 @@ impl NodeAnnouncementInfo {
}

/// Internet-level addresses via which one can connect to the node
pub fn addresses(&self) -> &Vec<SocketAddress> {
pub fn addresses(&self) -> &[SocketAddress] {
match self {
NodeAnnouncementInfo::Relayed(relayed) => {
&relayed.contents.addresses
Expand Down
18 changes: 16 additions & 2 deletions lightning/src/util/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,10 +656,24 @@ impl Readable for WithoutLength<UntrustedString> {
}
}

impl<'a, T: Writeable> Writeable for WithoutLength<&'a Vec<T>> {
trait AsWriteableSlice {
type Inner: Writeable;
fn as_slice(&self) -> &[Self::Inner];
}

impl<T: Writeable> AsWriteableSlice for &Vec<T> {
type Inner = T;
fn as_slice(&self) -> &[T] { &self }
}
impl<T: Writeable> AsWriteableSlice for &[T] {
type Inner = T;
fn as_slice(&self) -> &[T] { &self }
}

impl<S: AsWriteableSlice> Writeable for WithoutLength<S> {
#[inline]
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
for ref v in self.0.iter() {
for ref v in self.0.as_slice() {
v.write(writer)?;
}
Ok(())
Expand Down
Loading