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::path::Path;

use crate::cfg_host_parser::HostConfig;
use crate::error::*;


use super::caches::CacheOperations;
use super::cfg_parsers::{ConfigParser, read_file};
use crate::common::{ HOST_CFG_PATH, HOST_CFG_PATH_P};

/// An /etc/hosts file parser


impl CacheOperations for HostConfig
{
    fn is_reload_allowed(&self) -> bool 
    {
        return true;
    }
}

impl ConfigParser<HostConfig> for HostConfig
{
    fn parse_config() -> CDnsResult<Self>
    {
        let file_content = read_file(HOST_CFG_PATH)?;
        
        let ret = Self::parse_host_file_internal(file_content);

        return ret;
    }

    fn get_file_path() -> &'static Path
    {
        return &HOST_CFG_PATH_P;
    }

    fn is_default(&self) -> bool
    {
        return self.is_empty();
    }
}