Expand description
§csvenum-lib
Documentation for the csvenum-CLI lib
The following is meant for internal reference and the curious minded.
If you are looking to generate enums from a csv, refer to the Usage section of the readme
@github
§Structure
-
A .csv will be read into lines by the [reader] module.
-
The lines will get separated into values by the TableParser.
-
The TableParser will then create and validate the EnumTable.
-
The EnumTable will be passed to the constructor of the EnumModule that handles code generation and CLI options.
The thin CLI calls the generate_configured_enum_from_csv function which handles the above steps.
To construct an enumtable for testing, the code will look something like this:
use csvenum::TableParser;
let rows: Vec<&str> = vec![
"TYPES, &str, (usize,f64), bool",
"MyEnumName, Property1, Property2, Property3",
"Variant1, standard, (0,3.14), true",
"Variant2, medium, (0,9.82), false",
];
let table_parser = TableParser::from_csv_lines(rows);
assert!(table_parser.is_ok());
let enumtable = table_parser.unwrap().to_enumtable().unwrap();
assert_eq!(enumtable.get_name(), "MyEnumName");
// row and column indices have moved to only represent the associated values
let val_var1_prop2 = enumtable.get_value_by_col_row(1,0).unwrap();
assert_eq!(val_var1_prop2, "(0,3.14)");
§Code generation
To make writing the code-gen easier this crate implements a basic type system, consisting of enums and a unify’ing trait.
The base type being the RType that all other types are nested in.
The corresponding RTypeTrait is implemented for all nested types and provides QoL functions for validation and wrapping values in their respective container.
The code_gen module contains the necessary code for generation. A small example can be found in the code_gen::TextBlock documentation.
Re-exports§
pub use code_gen::EnumModule;
Modules§
Structs§
- Contains the options for code generation
- Gets created by the table parser
- Namespace container that holds the function to parse strings with nested values into a vector of values.
- Parses a Vec<&str> with CSV to an intermediate representation
Enums§
- Represents a container, like Vec
, Array [T; N] and Tuple(T,R) - Represents all numeric types
- Rust Type primitive (no value or name attached, except for enum), has functions for:
- Represents a reference
&
and lifetime<'a>
- Special types have vastly different behaviour than the other types and can not be directly inferred from a string representation (except for bool).
- Represents known string types
Traits§
- Trait to simplify handling types
Functions§
- Main function that stages file reading, parsing, validation and code gen