rdc
RDC
RDC - Rust Data Codegen
This crate is used to generate code for other languages from Rust's data structures. It can be used to generate DTO classes to make it easier to interact with other languages.
It currently supports only Java, but it can be easily extended to support other languages in the future.
It relies on the serde
crate to serialize and deserialize data.
For testing purposes it uses gradle to compile and run the generated Java code.
Java Examples
Simple struct
use ;
use JavaClass;
use ;
let classes: = rdc_java!.unwrap;
Struct with dependencies
You do not have to specify all the types that are used in your data structures. RDC will automatically add all the dependencies.
use ;
use JavaClass;
let classes: = rdc_java!.unwrap;
assert_eq!;
Enum
use ;
rdc_java!.unwrap;
Data enum
Data enum is a special type of enum that can contain data.
use ;
rdc_java!.unwrap;
Example JSON representations:
Generics
There is support for generics in RDC.
It works by generating a Java class for each combination of generic types.
Every used generic type should implement rdc::RDCType
trait.
Please note that this trait is implemented automatically by #[derive(RDC)]
.
use ;
let classes = rdc_java!.unwrap;
assert_eq!;
Writing
RDC can write the generated code to files.
use ;
use ;
let classes: = rdc_java!.unwrap;
write_java.unwrap;
Serde compatibility
You can use #[serde(rename = "new_name")]
to rename fields and it will be reflected in the generated code.
License: MIT