feat(iroh-base): Implement From
& Into
between NodeAddr
and NodeTicket
#2717
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Previously, when all you had was a
NodeTicket
, all you could get was a reference&NodeAddr
from it to use withEndpoint::connect
, which requires an ownedNodeAddr
.This adds
From
impls for converting betweenNodeTicket
andNodeAddr
, so you can callendpoint.connect(ticket.into())
.Breaking Changes
None - only additions.
Notes & open questions
When I originally raised this, I thought of making the
node_addr
argumentimpl Into<NodeAddr>
, but we have aninstrument(remote = %node_addr.node_id.fmt_sort)
annotation on that function. Due to ownership, it's hard to make that work withimpl Into<NodeAddr>
. As far as I can see there's three options:node_addr: impl Into<NodeAddr> + Clone
Endpoint::connect
into two functions, a public, outer one withnode_addr: impl Into<NodeAddr>
and without aninstrument
annotation, and an inner private one withnode_addr: NodeAddr
, but with aninstrument
annotation.node_addr: NodeAddr
with theinstrument
annotation and require users to call.into()
.I found the third option to be the simplest. @flub please let me know if that sounds good.
Change checklist
[ ] Tests if relevant.I honestly don't think we need tests for this.