| Crates.io | epics_gen |
| lib.rs | epics_gen |
| version | 0.2.2 |
| created_at | 2024-12-14 22:48:23.728416+00 |
| updated_at | 2025-01-06 08:19:47.997497+00 |
| description | Helpful macros for deserializing xlsx tables and serializing them as EPICS PVs |
| homepage | https://github.com/wtup/epics-gen |
| repository | https://github.com/wtup/epics-gen |
| max_upload_size | |
| id | 1483488 |
| size | 45,967 |
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 from XlsxString type to target typeFromXlsxFloat]: implements [FromXlsxData] trait for
conversion from XlsxFloat type to target typeAsRecord]: implements support for printing the record (serialize)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"
| 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.
| 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,
}