[GH-ISSUE #2493] Record set_data() without introspection (copying data from another Record directly) #1003

Open
opened 2026-03-16 01:14:08 +03:00 by kerem · 1 comment
Owner

Originally created by @thedeadliestcatch on GitHub (Oct 5, 2024).
Original GitHub issue: https://github.com/hickory-dns/hickory-dns/issues/2493

Consider the following code:

        // Iterate over the records
        let answers = lookup.record_iter();

        let mut mutated_answers: Vec<Record> = Vec::new();

        for answer in answers {
            let mut new_rec: Record = Record::new();
            new_rec.set_name(answer.name().clone());
            new_rec.set_record_type(answer.record_type());
            new_rec.set_ttl(answer.ttl());
            //new_rec.set_data(answer.data());
            mutated_answers.push(answer.clone());
        }

What is the idiomatic and correct way to create a mutable clone of the Record's inner data? Is there a way to modify the inner data "elegantly" prior to building a Response?

I also see that the from_rdata constructor has the same issue:

            let mut new_rec: Record = Record::from_rdata(answer.name().clone(), answer.ttl(), answer.data());
168 | ...: Record = Record::from_rdata(answer.name().clone(), answer.ttl(), answer.data());
    |               ------------------                                      ^^^^^^^^^^^^^ expected `RData`, found `Option<&RData>`
    |               |
    |               arguments to this function are incorrect
    |
    = note: expected enum `RData`
               found enum `std::option::Option<&RData>`

Thanks in advance!

Originally created by @thedeadliestcatch on GitHub (Oct 5, 2024). Original GitHub issue: https://github.com/hickory-dns/hickory-dns/issues/2493 Consider the following code: ``` // Iterate over the records let answers = lookup.record_iter(); let mut mutated_answers: Vec<Record> = Vec::new(); for answer in answers { let mut new_rec: Record = Record::new(); new_rec.set_name(answer.name().clone()); new_rec.set_record_type(answer.record_type()); new_rec.set_ttl(answer.ttl()); //new_rec.set_data(answer.data()); mutated_answers.push(answer.clone()); } ``` What is the idiomatic and correct way to create a mutable clone of the Record's inner data? Is there a way to modify the inner data "elegantly" prior to building a Response? I also see that the `from_rdata` constructor has the same issue: ``` let mut new_rec: Record = Record::from_rdata(answer.name().clone(), answer.ttl(), answer.data()); ``` ``` 168 | ...: Record = Record::from_rdata(answer.name().clone(), answer.ttl(), answer.data()); | ------------------ ^^^^^^^^^^^^^ expected `RData`, found `Option<&RData>` | | | arguments to this function are incorrect | = note: expected enum `RData` found enum `std::option::Option<&RData>` ``` Thanks in advance!
Author
Owner

@bluejekyll commented on GitHub (Mar 2, 2025):

Do you have an example of how you'd like this to work? Record implements Clone, which is how I would think you'd do what you want, but maybe I'm wrong.

<!-- gh-comment-id:2692841937 --> @bluejekyll commented on GitHub (Mar 2, 2025): Do you have an example of how you'd like this to work? Record implements Clone, which is how I would think you'd do what you want, but maybe I'm wrong.
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#1003
No description provided.