mhost 0.11.3

Fast, async DNS lookup library and CLI -- modern dig/host replacement with parallel multi-server queries, DoH, DoT, subdomain discovery, and zone verification
Documentation
// Copyright 2017-2021 Lukas Pustina <lukas@pustina.de>
//
// Derived from trust-dns by Benjamin Fry <benjaminfry@me.com>
// cf. https://github.com/bluejekyll/trust-dns
//
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms..

use hickory_resolver::Name;
use serde::{Deserialize, Serialize};

#[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize, Deserialize)]
#[allow(clippy::upper_case_acronyms)]
pub struct SRV {
    priority: u16,
    weight: u16,
    port: u16,
    target: Name,
}

impl SRV {
    pub fn new(priority: u16, weight: u16, port: u16, target: Name) -> SRV {
        SRV {
            priority,
            weight,
            port,
            target,
        }
    }

    pub fn priority(&self) -> u16 {
        self.priority
    }

    pub fn weight(&self) -> u16 {
        self.weight
    }

    pub fn port(&self) -> u16 {
        self.port
    }

    pub fn target(&self) -> &Name {
        &self.target
    }
}

#[doc(hidden)]
impl From<hickory_resolver::proto::rr::rdata::SRV> for SRV {
    fn from(srv: hickory_resolver::proto::rr::rdata::SRV) -> Self {
        SRV {
            priority: srv.priority(),
            weight: srv.weight(),
            port: srv.port(),
            target: srv.target().clone(),
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn srv_new_and_accessors() {
        let target = Name::from_utf8("sip.example.com.").unwrap();
        let srv = SRV::new(10, 20, 5060, target.clone());

        assert_eq!(srv.priority(), 10);
        assert_eq!(srv.weight(), 20);
        assert_eq!(srv.port(), 5060);
        assert_eq!(srv.target(), &target);
    }
}