[GH-ISSUE #1865] "into_<fields>" methods #798

Open
opened 2026-03-16 00:17:13 +03:00 by kerem · 7 comments
Owner

Originally created by @mattfbacon on GitHub (Dec 21, 2022).
Original GitHub issue: https://github.com/hickory-dns/hickory-dns/issues/1865

Consider this struct: https://docs.rs/trust-dns-proto/0.22.0/trust_dns_proto/rr/rdata/mx/struct.MX.html

It has an owned Name field, but there is no way to get that out of it; you can only get &Name.

For efficiency purposes, I would like to be able to do into_exchange to get Name from MX.

This applies in general to all similar data types.

Originally created by @mattfbacon on GitHub (Dec 21, 2022). Original GitHub issue: https://github.com/hickory-dns/hickory-dns/issues/1865 Consider this struct: https://docs.rs/trust-dns-proto/0.22.0/trust_dns_proto/rr/rdata/mx/struct.MX.html It has an owned Name field, but there is no way to get that out of it; you can only get &Name. For efficiency purposes, I would like to be able to do `into_exchange` to get Name from MX. This applies in general to all similar data types.
Author
Owner

@djc commented on GitHub (Dec 22, 2022):

Do you actually have a benchmark where this matters?

In general, pull requests for stuff like this are welcome! For this particular type, I wonder if we should just make the fields public instead...

<!-- gh-comment-id:1362542775 --> @djc commented on GitHub (Dec 22, 2022): Do you actually have a benchmark where this matters? In general, pull requests for stuff like this are welcome! For this particular type, I wonder if we should just make the fields public instead...
Author
Owner

@mattfbacon commented on GitHub (Dec 22, 2022):

I agree that making the fields public would be the best option if possible. I thought they were private for backwards-compatibility or something.

I don't think it makes a huge performance difference. It's just annoying to have to Clone when I would be able to take out the field.

<!-- gh-comment-id:1363312449 --> @mattfbacon commented on GitHub (Dec 22, 2022): I agree that making the fields public would be the best option if possible. I thought they were private for backwards-compatibility or something. I don't think it makes a huge performance difference. It's just annoying to have to Clone when I would be able to take out the field.
Author
Owner

@bluejekyll commented on GitHub (Dec 22, 2022):

Generally, I like keeping internal fields private, like you said @mattfbacon, for backward compatibility concerns. That being said, the RecordData types probably won't change, so maybe it's not a concern there?

<!-- gh-comment-id:1363314611 --> @bluejekyll commented on GitHub (Dec 22, 2022): Generally, I like keeping internal fields private, like you said @mattfbacon, for backward compatibility concerns. That being said, the RecordData types probably won't change, so maybe it's not a concern there?
Author
Owner

@mattfbacon commented on GitHub (Dec 22, 2022):

OK if making the fields public is acceptable then I will make a PR doing that soon.

<!-- gh-comment-id:1363412338 --> @mattfbacon commented on GitHub (Dec 22, 2022): OK if making the fields public is acceptable then I will make a PR doing that soon.
Author
Owner

@djc commented on GitHub (Dec 27, 2022):

Yeah, for RecordData fields I think making the fields public is probably reasonable.

<!-- gh-comment-id:1366195796 --> @djc commented on GitHub (Dec 27, 2022): Yeah, for `RecordData` fields I think making the fields public is probably reasonable.
Author
Owner

@mattfbacon commented on GitHub (Dec 30, 2022):

Were these structs generated automatically somehow?

<!-- gh-comment-id:1368095415 --> @mattfbacon commented on GitHub (Dec 30, 2022): Were these structs generated automatically somehow?
Author
Owner

@djc commented on GitHub (Dec 30, 2022):

Nope!

<!-- gh-comment-id:1368110783 --> @djc commented on GitHub (Dec 30, 2022): Nope!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hickory-dns#798
No description provided.