Skip to content
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

feat: extract match addr to type as a function #205

Merged
merged 5 commits into from
May 3, 2024

Conversation

CosminPerRam
Copy link
Contributor

I have seen the repeated usage of

match address {
    IpAddr::V4(_) => TYPE_A,
    IpAddr::V6(_) => TYPE_AAAA,
}

in multiple places, although this is a very simple operation, it could be extracted into a function (which is what this PR does).
I'm not really sure if the function name ip_address_to_type and its location are appropriate.

Copy link
Owner

@keepsimple1 keepsimple1 left a comment

Choose a reason for hiding this comment

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

Thanks for your PR! It's a nice refactoring! Minor comments inline.

@@ -52,6 +52,14 @@ pub const FLAGS_AA: u16 = 0x0400; // mask for Authoritative answer bit

pub type DnsRecordBox = Box<dyn DnsRecordExt + Send>;

#[inline]
pub const fn ip_address_to_type(address: IpAddr) -> u16 {
Copy link
Owner

Choose a reason for hiding this comment

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

nitpick: do you mind pass address as &IpAddr ?

IpAddr::V4(_) => zc.send_query(hostname, TYPE_A),
IpAddr::V6(_) => zc.send_query(hostname, TYPE_AAAA),
}
zc.send_query(hostname, ip_address_to_type(*ip_addr));
Copy link
Owner

Choose a reason for hiding this comment

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

If we pass &IpAddr for the function, then no need to have * here.

Copy link
Owner

@keepsimple1 keepsimple1 left a comment

Choose a reason for hiding this comment

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

Nice! LGTM, thanks!

@keepsimple1 keepsimple1 merged commit 19d2161 into keepsimple1:main May 3, 2024
3 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.

None yet

2 participants