Skip to content

add Multiaddr::ip_addr - #139

Merged
jxs merged 1 commit into
multiformats:masterfrom
jxs:add-ip-addr
Sep 29, 2026
Merged

jxs merged 1 commit into
multiformats:masterfrom
jxs:add-ip-addr

Conversation

@jxs

@jxs jxs commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@elenaf9 elenaf9 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One idea, but current implementation also lgtm.

Comment thread src/lib.rs
Comment on lines +232 to +237
pub fn ip_addr(&self) -> Option<IpAddr> {
self.iter().find_map(|p| match p {
Protocol::Ip4(addr) => Some(IpAddr::V4(addr)),
Protocol::Ip6(addr) => Some(IpAddr::V6(addr)),
_ => None,
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already implemented From<IpAddr> for Multiaddr. Would it maybe make sense to just analogously implement TryFrom<&Multiaddr> for IpAddr?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huh I like that! But we'd need to add a new Error variant and have Err instead of None for the return type. It would also be less visible the method

@jxs
jxs merged commit 3e765c1 into multiformats:master Sep 29, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants