rustyphoenixlecture 1.2.0

This project aims to provide a simple a powerfull lecture compilation to generate html web sites
/***************************************
	Auteur : Pierre Aubert
	Mail : pierre.aubert@lapp.in2p3.fr
	Licence : CeCILL-C
****************************************/

use std::{collections::HashMap, fs, path::PathBuf};
use serde::Deserialize;
use toml::{self, de::Error};

///Environment of the lecture
#[derive(Debug, Clone, Deserialize)]
pub struct PEnvironment{
	///Name of the environment
	pub name: String,
	///Main balise to use around this environment
	pub balise: String,
	///True if the paragraph are allowed in this environment
	pub is_paragraph_allowed: bool,
	///Image to illustrate the environment (could be empty)
	pub image: String,
	///Css style of the environment
	pub style: String,
}

///Vector of environement in a file
#[derive(Debug, Clone, Deserialize)]
pub struct PVecEnvironment{
	///Vector of all environement in a file
	environment: Vec<PEnvironment>,
}

///Load the PVecEnvironment configuration file
/// # Parameters
/// - `filename` : name of the PVecEnvironment configuration file (in toml)
/// # Returns
/// Replace parsed PVecEnvironment configuration or error on fail
fn load_vec_environement(filename: &PathBuf) -> Result<PVecEnvironment, Error> {
	let config: PVecEnvironment = match fs::read_to_string(filename) {
		Ok(str) => match toml::from_str(&str){
			Ok(value) => value,
			Err(error) => panic!("load_vec_environement : cannot parse file {:?}, parsing error {}", filename, error)
		},
		Err(err) => panic!("load_vec_environement : cannot read file {:?}, error: {}", filename, err)
	};
	Ok(config)
}

///Update the map of environment
/// # Parameters
/// - `map_environement` : map of environement to be updated
/// - `vec_env_name` : vector of environement names to be updated
/// - `filename` : name of the PVecEnvironment configuration file (in toml)
pub fn update_map_environment(map_environement: &mut HashMap<String, PEnvironment>, vec_env_name: &mut Vec<String>, filename: &PathBuf){
	let vec_environement: PVecEnvironment = match load_vec_environement(filename) {
		Ok(vecenv) => vecenv,
		Err(err) => panic!("update_map_environment : cannot read file {:?}, error: {}", filename, err)
	};
	for env in vec_environement.environment {
		map_environement.insert(env.name.clone(), env.clone());
		vec_env_name.push(env.name.clone());
	}
}