|
|
|
@ -1,6 +1,6 @@
|
|
|
|
|
import chalk from "chalk";
|
|
|
|
|
import { CompileTarget } from "../compile";
|
|
|
|
|
import { TypeDefinition, EnumDefinition, ServiceDefinition, Step } from "../ir";
|
|
|
|
|
import { TypeDefinition, EnumDefinition, ServiceDefinition, Step, IR } from "../ir";
|
|
|
|
|
import { lineAppender, LineAppender } from "../utils";
|
|
|
|
|
|
|
|
|
|
const conversion = {
|
|
|
|
@ -72,17 +72,28 @@ export class RustTarget extends CompileTarget<{ rust_crate: string }> {
|
|
|
|
|
a(0, `pub struct ${definition.name} {`);
|
|
|
|
|
for (const field of definition.fields) {
|
|
|
|
|
a(1, `#[allow(non_snake_case)]`);
|
|
|
|
|
|
|
|
|
|
let fn = `pub ${field.name}:`;
|
|
|
|
|
if (field.name == "type") {
|
|
|
|
|
// TODO: Add other keywords as well!
|
|
|
|
|
console.log(
|
|
|
|
|
chalk.yellow("[RUST] WARNING:"),
|
|
|
|
|
"Field name 'type' is not allowed in Rust. Renaming to 'type_'"
|
|
|
|
|
);
|
|
|
|
|
fn = `pub type_:`;
|
|
|
|
|
a(1, `#[serde(rename = "type")]`);
|
|
|
|
|
}
|
|
|
|
|
if (field.array) {
|
|
|
|
|
a(1, `pub ${field.name}: Vec<${toRustType(field.type)}>,`);
|
|
|
|
|
a(1, `${fn} Vec<${toRustType(field.type)}>,`);
|
|
|
|
|
} else if (field.map) {
|
|
|
|
|
a(
|
|
|
|
|
1,
|
|
|
|
|
`pub ${field.name}: HashMap<${toRustType(
|
|
|
|
|
`${fn} HashMap<${toRustType(
|
|
|
|
|
field.map
|
|
|
|
|
)}, ${toRustType(field.type)}>,`
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
a(1, `pub ${field.name}: ${toRustType(field.type)},`);
|
|
|
|
|
a(1, `${fn} ${toRustType(field.type)},`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
a(0, `}`);
|
|
|
|
@ -219,6 +230,7 @@ export class RustTarget extends CompileTarget<{ rust_crate: string }> {
|
|
|
|
|
a(0, `}`);
|
|
|
|
|
a(0, ``);
|
|
|
|
|
a(0, `impl ${definition.name}Handler {`);
|
|
|
|
|
//TODO: Maybe add a new definition like, pub fn new2<T>(implementation: T) where T: ${definition.name} + Sync + Send + 'static {}
|
|
|
|
|
a(
|
|
|
|
|
1,
|
|
|
|
|
`pub fn new(implementation: Box<dyn ${definition.name} + Sync + Send + 'static>) -> Arc<Self> {`
|
|
|
|
|