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

Make sure Found{Hosts, Addrs} have is_empty and len methods #316

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/resolv/lookup/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ pub async fn lookup_addr<R: Resolver>(
pub struct FoundAddrs<R: Resolver>(R::Answer);

impl<R: Resolver> FoundAddrs<R> {
pub fn is_empty(&self) -> bool {
self.len() == 0
}

pub fn len(&self) -> usize {
self.0.as_ref().header_counts().ancount() as usize
}

/// Returns an iterator over the host names.
pub fn iter(&self) -> FoundAddrsIter<'_, R::Octets>
where
Expand Down
14 changes: 14 additions & 0 deletions src/resolv/lookup/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,20 @@ impl<R: Resolver> FoundHosts<R> {
true
}

pub fn len(&self) -> usize {
let aaaa = self
.aaaa
.as_ref()
.map_or(0, |m| m.as_ref().header_counts().ancount());

let a = self
.a
.as_ref()
.map_or(0, |m| m.as_ref().header_counts().ancount());

(aaaa + a) as usize
}

/// Returns a reference to one of the answers.
fn answer(&self) -> &R::Answer {
match self.aaaa.as_ref() {
Expand Down
Loading