podserve 0.2.0

Spin up an RSS podcast feed webserver from a directories of MP3s
use failure::Error;
use serde_derive::{Deserialize, Serialize};
use std::fs;
use std::io::prelude::*;
use std::path::PathBuf;
use toml;

#[derive(Debug, Deserialize, Serialize)]
pub struct Config {
    pub title: String,
    pub description: String,
}

impl Default for Config {
    fn default() -> Self {
        Self {
            title: "PodServe Feed".to_string(),
            description: "A podcast feed generated by PodServe (https://github.com/passy/podserve)"
                .to_string(),
        }
    }
}

pub fn read(path: &PathBuf) -> Result<Config, Error> {
    let mut input = String::new();
    fs::File::open(path).and_then(|mut f| f.read_to_string(&mut input))?;
    toml::from_str(&input).map_err(|e| e.into())
}

pub fn write(config: &Config, path: &PathBuf) -> Result<(), Error> {
    let content = toml::to_string_pretty(config)?;
    fs::File::create(path)
        .and_then(|mut f| f.write_all(content.as_bytes()))
        .map_err(|e| e.into())
}