technitium 0.4.0

Typed async Rust client for the Technitium DNS Server API
Documentation
use serde::{Deserialize, Serialize};

use crate::types::record::RecordType;

/// DNS transport protocol for query resolution.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum DnsProtocol {
    Udp,
    Tcp,
    Tls,
    Https,
    Quic,
}

impl std::fmt::Display for DnsProtocol {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Udp => write!(f, "Udp"),
            Self::Tcp => write!(f, "Tcp"),
            Self::Tls => write!(f, "Tls"),
            Self::Https => write!(f, "Https"),
            Self::Quic => write!(f, "Quic"),
        }
    }
}

/// A single DNS record in a query response.
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct DnsRecord {
    /// The record name.
    pub name: String,
    /// The record type.
    #[serde(rename = "Type")]
    pub record_type: RecordType,
    /// Record-specific data.
    #[serde(flatten)]
    pub data: serde_json::Value,
}

/// Wrapper for the DNS client resolve response.
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct DnsResolveResponse {
    pub result: DnsQueryResult,
}

/// Result of a DNS query resolution.
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct DnsQueryResult {
    /// Answer section records.
    #[serde(default)]
    pub answer: Vec<DnsRecord>,
    /// Authority section records.
    #[serde(default)]
    pub authority: Vec<DnsRecord>,
    /// Additional section records.
    #[serde(default)]
    pub additional: Vec<DnsRecord>,
    /// All other fields (metadata, EDNS, etc.).
    #[serde(flatten)]
    pub extra: serde_json::Value,
}