elastic-mapping-macro 0.1.0

Procedural macros for elastic-mapping - generate Elasticsearch mappings from Rust types
Documentation
use crate::{
    DocumentField, MappingProperty, codegen::IterableProperties, error::GeneratorError,
    rename::RenameCasing,
};

/// Generates mapping for structs
pub(crate) fn gen_struct(
    fields: &[DocumentField],
    rename_all: Option<RenameCasing>,
) -> Result<(Vec<MappingProperty>, Vec<IterableProperties>), GeneratorError> {
    let mut properties = Vec::new();
    let mut iterable = Vec::new();

    for field in fields {
        if field.flatten {
            // Flattened fields are iterated at runtime
            let ty = &field.ty;
            iterable.push(IterableProperties {
                source: quote::quote! {
                    <#ty as elastic_mapping::MappingType>::fields()
                },
            });
        } else {
            // Regular fields become properties
            properties.push(field.gen_mapping(rename_all));
        }
    }

    Ok((properties, iterable))
}