rustyphoenixcheckstreamderive 1.4.0

This C++ library provides functions to check data easily. Adding type can be done be defining only one function per extra type you wan to use ! This is the Rust equivalent of https://gitlab.in2p3.fr/CTA-LAPP/PHOENIX_LIBS2/serialize-io/PhoenixCheckStream
Documentation
/***************************************
	Auteur : Pierre Aubert
	Mail : pierre.aubert@lapp.in2p3.fr
	Licence : CeCILL-C
****************************************/

extern crate proc_macro;

use proc_macro::TokenStream;

use syn::{
	parse_macro_input, DeriveInput, Fields, Data
};

///Get the names of attributes of a struct
/// # Parameters
/// - `input` - DeriveInput
/// # Returns
/// vector of attributes names of the struct if it does exist, empty vector otherwise
fn get_struct_attribute_name(input: &DeriveInput) -> Vec<String> {
	let mut vec_name: Vec<String> = vec![];
	match &input.data {
		Data::Enum(_) => {}
		Data::Struct(current_struct) => match &current_struct.fields {
			Fields::Unit => {}
			Fields::Named(fields) => {
				for field in fields.named.iter() {
					match &field.ident {
						Some(ident) => vec_name.push(String::from(format!("{}", ident))),
						None => {},
					}
				}
			}
			Fields::Unnamed(_fields) => {}
		},
		Data::Union(_u) => {}
	}
	return vec_name;
}

///Implement automatically the `PCheckStream` trait for a given **struct** so it can be used with `datastream_read` and `datastream_write` and is compatible with the original [PhoenixCheckStream](https://gitlab.in2p3.fr/CTA-LAPP/PHOENIX_LIBS2/serialize-io/PhoenixCheckStream)
/// # Parameters
/// - `input` : input **TokenStream** to be treated by the macro
/// # Returns
/// Modified **TokenStream** with implementation of `PCheckStream` trait
#[proc_macro_derive(PhoenixCheckStream)]
pub fn derive_custom_static_print_fn(input: TokenStream) -> TokenStream {
	let input = parse_macro_input!(input as DeriveInput);
	
	let vec_name = get_struct_attribute_name(&input);
	
	let name = input.ident;
	let mut body = String::from(format!("impl PCheckStream for {} ", name));
	body += &String::from("{");
	body += &String::from("fn check_value(&self, field_description: &str, reference: &Self) -> Result<bool, String>{");
	//Let's implement the write method
	for attr_name in vec_name.iter() {
		body += &String::from(format!("phoenix_check_stream!(&(field_description.to_owned() + &String::from(\"\\n- {}::{}\")), self.{}, &reference.{});", name, attr_name, attr_name, attr_name));
	}
	body += &String::from("Ok(true)");
	body += &String::from("}");
	
	body += &String::from("}");
	body.parse().unwrap()
}