add-macro-impl-from 0.1.1

Implementation of trait 'From<T>'
Documentation
use crate::prelude::*;
use proc_macro2::TokenStream;
use venial::{ Struct, AttributeValue };
use quote::quote;

// Implementation of trait 'From' for structures
pub(crate) fn impl_from_struct(data: Struct) -> Result<TokenStream> {
    let name = &data.name;
    let mut output = quote!{};

    // reading attributes:
    let attrs = data.attributes;
    for attr in attrs.into_iter() {
        if !check_attr_name(&attr, "from") { continue };

        match attr.value {
            AttributeValue::Group(_, tokens) => {
                // parse attribute arguments:
                let (ty, expr) = parse_attr_arguments(&tokens)?;

                // generate tokens:
                output.extend(quote! {
                    impl ::core::convert::From<#ty> for #name {
                        fn from(v: #ty) -> Self {
                            #expr
                        }
                    }
                });
            },

            _ => return Err(Error::IncorrectAttribute)
        }
    }

    Ok(output)
}