zencan_macro/
lib.rs

1// use eds_parser::ElectronicDataSheet;
2
3extern crate proc_macro;
4use std::str::FromStr as _;
5use zencan_build::device_config_to_string;
6use zencan_common::device_config::DeviceConfig;
7
8/// Macro to build an object dict from inline device config TOML
9#[proc_macro]
10pub fn build_object_dict(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
11    let str_literal: syn::LitStr =
12        syn::parse(input).expect("Expected string literal as macro argument");
13    let device =
14        DeviceConfig::load_from_str(&str_literal.value()).expect("Error parsing device config");
15    proc_macro::TokenStream::from_str(&device_config_to_string(&device, true).unwrap()).unwrap()
16}