rustyphoenixlecture 1.3.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::{fs, path::PathBuf};
use serde::Deserialize;
use toml::{self, de::Error};

///Speaker of the school / webinar / lecture
#[derive(Debug, Clone, Deserialize)]
pub struct PSpeaker{
	///Name of the speaker
	pub name: String,
	///Title of the speaker
	pub title: String,
	///Label to refer to the speaker
	pub label: String,
	///Function / job of the speaker
	pub function: String,
	///Affiliation of the speaker
	pub affiliation: String,
	///Destription of the speaker in markdown
	pub description: String,
}

///Vector of speakers of the school / webinar / lecture
#[derive(Debug, Clone, Deserialize)]
pub struct PVecSpeaker{
	///Vector of all speaker of the school / webinar / lecture
	pub speaker: Vec<PSpeaker>,
}

///Load the lecture configuration file
/// # Parameters
/// - `filename` : name of the speakers configuration file (in toml)
/// # Returns
/// Vector of Speaker or error on fail
pub fn load_vec_speaker(filename: &PathBuf) -> Result<PVecSpeaker, Error> {
	let vec_speaker: PVecSpeaker = match fs::read_to_string(filename) {
		Ok(str) => match toml::from_str(&str){
			Ok(value) => value,
			Err(error) => panic!("load_vec_speaker : cannot parse file {:?}\n\tParsing error {}", filename, error)
		},
		Err(err) => panic!("load_vec_speaker : cannot read file {:?}\n\tError: {}", filename, err)
	};
	Ok(vec_speaker)
}


#[cfg(test)]
mod tests{
	use super::*;
	
	///Test the load vector of speaker
	#[test]
	fn test_load_vec_speaker(){
		let vec_speaker: PVecSpeaker = load_vec_speaker(&PathBuf::from("tests/timetable/speaker.toml")).unwrap();
		assert_eq!(vec_speaker.speaker.len(), 1);
		let speaker = vec_speaker.speaker.first().unwrap();
		assert_eq!(speaker.name, String::from("Pierre Aubert"));
		assert_eq!(speaker.title, String::from("Dr"));
		assert_eq!(speaker.label, String::from("pierre_aubert"));
		assert_eq!(speaker.function, String::from("Research Engineer at LAPP"));
		assert_eq!(speaker.affiliation, String::from("LAPP / IN2P3 / CNRS"));
		assert_eq!(speaker.description, String::from("Pierre Aubert is a software developer specialized in code optimization for CPUs and GPUs, mainly on modern C++, Rust and also on Python. He works at LAPP, the Laboratory of Annecy of Particle Physics."));
		
	}
}