cdns_rs/sync/
cfg_parsers.rs

1/*-
2 * cdns-rs - a simple sync/async DNS query library
3 * 
4 * Copyright (C) 2020  Aleksandr Morozov
5 * 
6 * Copyright 2025 Aleksandr Morozov
7 * 
8 * Licensed under the EUPL, Version 1.2 or - as soon they will be approved by
9 * the European Commission - subsequent versions of the EUPL (the "Licence").
10 * 
11 * You may not use this work except in compliance with the Licence.
12 * 
13 * You may obtain a copy of the Licence at:
14 * 
15 *    https://joinup.ec.europa.eu/software/page/eupl
16 * 
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the Licence is distributed on an "AS IS" basis, WITHOUT
19 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
20 * Licence for the specific language governing permissions and limitations
21 * under the Licence.
22 */
23
24
25/// This file contains the config file parsers.
26
27use std::io::Read;
28use std::fs::File;
29
30use std::path::Path;
31
32use crate::{internal_error_map, error::*};
33
34
35pub trait ConfigParser<T>
36{
37    fn parse_config() -> CDnsResult<T>;
38
39    fn get_file_path() -> &'static Path;
40
41    fn is_default(&self) -> bool;
42}
43
44pub(super)
45fn read_file(path: &str) -> CDnsResult<String>
46{
47    let mut file = 
48        File::open(path).map_err(|e| internal_error_map!(CDnsErrorType::InternalError, "{}", e))?;
49
50    let mut file_content: String = String::new();
51
52    file.read_to_string(&mut file_content).map_err(|e| internal_error_map!(CDnsErrorType::InternalError, "{}", e))?;
53
54    return Ok(file_content);
55}
56
57
58