diff --git a/contrib/quirky_binder_csv/Cargo.toml b/contrib/quirky_binder_csv/Cargo.toml index 7e235d3..0a35697 100644 --- a/contrib/quirky_binder_csv/Cargo.toml +++ b/contrib/quirky_binder_csv/Cargo.toml @@ -7,7 +7,7 @@ license-file = "../LICENSE" description = "Quirky Binder - CSV" documentation = "https://docs.rs/quirky_binder_csv" repository = "https://github.com/arnodb/quirky_binder" -readme = "../README.md" +readme = "README.md" [dependencies] getset = "0.1" diff --git a/contrib/quirky_binder_csv/README.md b/contrib/quirky_binder_csv/README.md new file mode 100644 index 0000000..01835cc --- /dev/null +++ b/contrib/quirky_binder_csv/README.md @@ -0,0 +1,42 @@ +# Quirky Binder - CSV + +`quirky_binder_csv` helps reading and writing CSV files. + +## Setup + +* add `quirky_binder_csv` to `[build-dependencies]` +* add `csv = "1"` to `[dependencies]` + +## Read + +``` +use quirky_binder_csv::read_csv; + +{ + ( + read_csv( + input_file: "input/hello_universe.csv", + fields: [("hello", "String"), ("universe", "usize")], + has_headers: true, + ) + - ... + ) +} +``` + +## Write + +``` +use quirky_binder_csv::write_csv; + +{ + ( + ... + - write_csv( + output_file: "output/hello_universe.csv", + has_headers: true, + ) + ) +} +``` + diff --git a/recipes/Cargo.toml b/recipes/Cargo.toml index a5e86cf..3df8a42 100644 --- a/recipes/Cargo.toml +++ b/recipes/Cargo.toml @@ -1,5 +1,6 @@ [workspace] resolver = "2" members = [ + "csv", "hello_world", ] diff --git a/recipes/csv/.gitignore b/recipes/csv/.gitignore new file mode 100644 index 0000000..1f57b97 --- /dev/null +++ b/recipes/csv/.gitignore @@ -0,0 +1 @@ +/output diff --git a/recipes/csv/Cargo.toml b/recipes/csv/Cargo.toml new file mode 100644 index 0000000..840f88d --- /dev/null +++ b/recipes/csv/Cargo.toml @@ -0,0 +1,30 @@ +[package] +name = "csv" +version = "0.1.0" +edition = "2021" + +[dependencies] +anyhow = "1" +csv = "1" +fallible-iterator = "0.3" +quirky_binder_support = { path = "../../quirky_binder_support" } +serde = "1" +static_assertions = "1" +truc_runtime = { git = "https://github.com/arnodb/truc.git" } + +# quirky_binder_monitor +chrono = { version = "0.4", optional = true } +self-meter = { version = "0.6", optional = true } +tracking-allocator = { version = "0.4", optional = true } + +[features] +default = [] +quirky_binder_monitor = ["chrono", "self-meter", "tracking-allocator"] + +[build-dependencies] +handlebars = "4" +quirky_binder = { path = "../../quirky_binder" } +quirky_binder_csv = { path = "../../contrib/quirky_binder_csv" } +quirky_binder_lang = { path = "../../quirky_binder_lang" } +serde = { version = "1", features = ["derive"] } +truc = { git = "https://github.com/arnodb/truc.git" } diff --git a/recipes/csv/README.md b/recipes/csv/README.md new file mode 100644 index 0000000..c0b3fa4 --- /dev/null +++ b/recipes/csv/README.md @@ -0,0 +1,13 @@ +# Quirky Binder Recipe - csv + +## Description + +Quirky Binder allows reading and writing CSV files with the help of `quirky_binder_csv` crate. + +## Setup + +In addition to mandatory quirky binder dependencies: + +* add `quirky_binder_csv` to `[build-dependencies]` +* add `csv` to `[dependencies]` (see `quirky_binder_csv` documentation) + diff --git a/recipes/csv/build.rs b/recipes/csv/build.rs new file mode 100644 index 0000000..2dc9951 --- /dev/null +++ b/recipes/csv/build.rs @@ -0,0 +1,25 @@ +use std::path::Path; + +use quirky_binder::{prelude::*, quirky_binder}; +use truc::record::type_resolver::{StaticTypeResolver, TypeResolver}; + +fn main() { + quirky_binder!(include("main.qb")); + + let type_resolver = { + let mut resolver = StaticTypeResolver::new(); + resolver.add_std_types(); + resolver + }; + + let graph = quirky_binder_main(GraphBuilder::new( + &type_resolver, + ChainCustomizer::default(), + )) + .unwrap_or_else(|err| { + panic!("{}", err); + }); + + let out_dir = std::env::var("OUT_DIR").unwrap(); + graph.generate(Path::new(&out_dir)).unwrap(); +} diff --git a/recipes/csv/input/hello_universe.csv b/recipes/csv/input/hello_universe.csv new file mode 100644 index 0000000..e104716 --- /dev/null +++ b/recipes/csv/input/hello_universe.csv @@ -0,0 +1,2 @@ +hello,universe +world,42 diff --git a/recipes/csv/main.qb b/recipes/csv/main.qb new file mode 100644 index 0000000..781477c --- /dev/null +++ b/recipes/csv/main.qb @@ -0,0 +1,21 @@ +use quirky_binder_csv::{read_csv, write_csv}; + +{ + ( + read_csv( + input_file: "input/hello_universe.csv", + fields: [("hello", "String"), ("universe", "usize")], + has_headers: true, + ) + - write_csv( + output_file: "output/hello_universe.csv", + has_headers: true, + ) + ) +} + +#( + name: "quirky_binder_monitor", + feature: "quirky_binder_monitor", +) +{ ( quirky_binder::filter::monitor::monitor() ) } diff --git a/recipes/csv/src/main.rs b/recipes/csv/src/main.rs new file mode 100644 index 0000000..36b7ee9 --- /dev/null +++ b/recipes/csv/src/main.rs @@ -0,0 +1,18 @@ +use quirky_binder_support::chain::configuration::ChainConfiguration; + +#[macro_use] +extern crate static_assertions; + +#[allow(dead_code)] +#[allow(clippy::borrowed_box)] +#[allow(clippy::module_inception)] +mod chain { + include!(concat!(env!("OUT_DIR"), "/chain.rs")); +} + +quirky_binder_support::tracking_allocator_static!(); + +#[quirky_binder_support::tracking_allocator_main] +fn main() { + chain::main(ChainConfiguration::default()).unwrap(); +}