5 releases
new 0.2.1 | Dec 20, 2024 |
---|---|
0.2.0 | Dec 20, 2024 |
0.1.2 | Dec 17, 2024 |
0.1.1 | Dec 17, 2024 |
0.1.0 | Dec 14, 2024 |
#151 in Procedural macros
297 downloads per month
21KB
280 lines
epics-gen
epics-gen is a set of helper macros that help developers create parsers for serializing xlsx spreadsheets into data structures and deserializing them as EPICS PVs.
Macros exposed by this library:
FromXlsxRow
: implements support for converting xlsx rows into structures (deserialize)FromXlsxString
: implements [FromXlsxData] trait for xlsx conversion fromXlsxString
type to target typeFromXlsxFloat
: implements [FromXlsxData] trait for conversion fromXlsxFloat
type to target type
AsRecord
: implements support for printing the record (serialize)
Including epics-gen in Your Project
Import epics_gen
and epics_gen_macros
into your project by adding the
following lines to your Cargo.toml. epics_gen_macros
contains the macros
needed to derive all the traits in epics-gen.
[dependencies]
epics_gen = "0.1"
epics_gen_macros = "0.1"
Macros
Macro | Description |
---|---|
[FromXlsxRow] | Converts xlsx table row to a target struct (deserialization). |
[FromXlsxString] | Converts XlsxString to target type. |
[FromXlsxFloat] | Converts XlsxFloat to target type. |
[AsRecord] | Implements as_record function to type (serialization). |
#[derive(FromXlsxString)]
enum RowId {
First,
Second,
Third,
Fourth,
}
#[derive(FromXlsxFloat)]
struct TestFloat(f64);
#[derive(FromXlsxRow)]
struct TargetStruct {
row_id: RowId,
float1: CustomFloat,
float2: CustomFloat,
}
let mut workbook: XlsxWorkbook = open_workbook("tests/test_parser1.xlsx")
.expect("xlsx file for this test is missing!");
let parser = epics_gen::ParserBuilder::new(&mut workbook)
.add_sheet("SheetName")
.add_table("TableName")
.build();
let parsed: Vec<TargetStruct> = parser.parse();
Note that an external library calamine
is used to read and store xlsx
files and data. The used structures and functions from calamine are reexported
in this crate convenience.
AsRecord attributes
Attribute | Description |
---|---|
[rec_name] | Sets record name of struct. |
[rec_type] | Define record type. |
[field] | Define field type. |
[subst] | Define substitution pattern. |
[repr] | Define representation type of member. |
[fmt] | Override member format. |
Example:
#[derive(AsRecord)]
#[record(rec_name = "$(P)Voltage", rec_type = "ao")]
struct TestStruct {
#[record(field = "DESC")]
desc: &'static str,
#[record(field = "EGU")]
egu: &'static str,
#[record(field = "VAL")]
val: f64,
}
Dependencies
~11MB
~260K SLoC