1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/*
 * Copyright (c) Gabriel Amihalachioaie, SimpleG 2023.
 */

use std::path::PathBuf;

use serde_yaml::Value;

use crate::error::Error;

#[derive(Default)]
pub struct ConfigReader {}

impl ConfigReader {
    pub fn read(&self, config_file_path: PathBuf) -> Result<Value, Error> {
        let result = std::fs::read_to_string(config_file_path);

        match result {
            Ok(yaml) => match serde_yaml::from_str(yaml.as_str()) {
                Ok(value) => Ok(value),
                Err(error) => Err(error.into()),
            },
            Err(error) => Err(error.into()),
        }
    }
}