cdns-rs 1.2.2

A native Sync/Async Rust implementation of client DNS resolver.
Documentation
/*-
 * cdns-rs - a simple sync/async DNS query library
 * 
 * Copyright (C) 2020  Aleksandr Morozov
 * 
 * Copyright (C) 2025 Aleksandr Morozov
 * 
 * The syslog-rs crate can be redistributed and/or modified
 * under the terms of either of the following licenses:
 *
 *   1. the Mozilla Public License Version 2.0 (the “MPL”) OR
 *                     
 *   2. EUROPEAN UNION PUBLIC LICENCE v. 1.2 EUPL © the European Union 2007, 2016
 */

use std::fmt;
use std::hash::{Hash, Hasher};

use crate::{CDnsError, CDnsResult};

use super::common::{QDnsName, QType};



#[derive(Debug, Clone, PartialEq, Eq)]
pub struct QDnsReq
{
    req_name: QDnsName,
    qtype: QType,
}

impl Hash for QDnsReq
{
    fn hash<H: Hasher>(&self, state: &mut H) 
    {
        self.req_name.hash(state);
    }
}


impl fmt::Display for QDnsReq
{
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result 
    {
        write!(f, "{} {}", self.req_name, self.qtype)
    }
}

impl QDnsReq
{
    pub(crate)
    fn new(req_name: QDnsName, qtype: QType) -> QDnsReq
    {
        return Self { req_name: req_name, qtype: qtype };
    }

    pub(crate)
    fn new_into<R>(req_name: R, qtype: QType) -> CDnsResult<QDnsReq>
    where R: TryInto<QDnsName, Error = CDnsError>
    {
        return Ok( Self { req_name: req_name.try_into()?, qtype: qtype } );
    }

    pub(crate) 
    fn get_type(&self) -> &QType
    {
        return &self.qtype;
    }

    pub(crate) 
    fn get_req_name(&self) -> &QDnsName
    {
        return &self.req_name;
    }
}