Crates.io | avrogen |
lib.rs | avrogen |
version | 0.1.5 |
source | src |
created_at | 2024-08-21 13:05:44.890178 |
updated_at | 2024-09-09 20:41:36.037999 |
description | This program allow allow to generate rust code from avro definition files. Modules are created from namespace information |
homepage | https://github.com/polo-asm/avrogen |
repository | https://github.com/polo-asm/avrogen |
max_upload_size | |
id | 1346519 |
size | 86,321 |
If you are not familiar with build scripts you can read the rust documentation about build scripts
You can use this crate to generate files in your rust project.
To do that you need to add the crate to your build dependencies in the Cargo.toml
file.
[build-dependencies]
avrogen = "0.1.3" # Update if needed
Then you need to add a build.rs
file with this kind of content:
use avrogen::Avrogen;
fn main(){
let builder= avrogen::Avrogen::new()
.add_source("Schemas/*.avsc")
.output_folder_from_str("src/");
builder.execute().expect("Impossible to generate rust files from avsc files");
println!("cargo::rerun-if-changed=Schemas/");
}
You can also generate the classes in your target folder using OUT_DIR environment variable.
avrogen --help
show you this help:
This program allow allow to generate rust code from avro definition files.
The code generated can be in a modul hierarchy and in the future we will generate a single file module structure.
Usage: avrogen [OPTIONS]
Options:
-s, --source [<SOURCE>...]
Source to use by the generator, use stdin if source isn't specified.
The source use glob format, you can use multiple source arguments. For simple search: ./MyFolder/*.avsc. For recursive search: ./MyFolder/**/*.avsc
-n, --default-namespace <DEFAULT_NAMESPACE>
Allow to define a default namespace for generated code. All namespace generated will be in this default namespace
-o, --output-folder <OUTPUT_FOLDER>
[default: ./]
-v, --verbose...
More output per occurrence
-q, --quiet...
Less output per occurrence
-h, --help
Print help (see a summary with '-h')
-V, --version
Print version
This tool generate rust modules and classes from asvc files.
The tool generate the same module structure than the namespace in the avsc files. This allow to have multiple types with the same
We can add a default namespace (module structue). This allow to generate all code in a SubNamespace.
Even if your asvc don't follow the rust naming conventions, the tool will generate files with good naming conventions.
snake_case
UpperCamelCase
snake_case
If a field/struct/module use a Rust reserved keyword a prefix will be added.
Some attributes are added to do the mapping between the asvc name and the sanitized name in the rust code.
This tool generate date fields which use chrono
crate. Ensure that you have added this crate in your project with the command:
cargo add chrono -F serde
This tool generate Guid fields which use uuid
crate. Ensure that you have added this crate in your project with the command:
cargo add uuid