Add allow_non_snake on fields in rust

This commit is contained in:
Fabian Stamm 2022-12-28 10:19:45 +01:00
parent 46aff0c61b
commit a291851b5a
4 changed files with 8 additions and 3 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@hibas123/jrpcgen", "name": "@hibas123/jrpcgen",
"version": "1.2.0", "version": "1.2.2",
"main": "lib/index.js", "main": "lib/index.js",
"license": "MIT", "license": "MIT",
"packageManager": "yarn@3.1.1", "packageManager": "yarn@3.1.1",

View File

@ -4,13 +4,15 @@ import yargs from "yargs";
import { hideBin } from "yargs/helpers"; import { hideBin } from "yargs/helpers";
import startCompile, { Target, Targets } from "./process"; import startCompile, { Target, Targets } from "./process";
const pkg = require("../package.json");
import dbg from "debug"; import dbg from "debug";
const log = dbg("app"); const log = dbg("app");
dbg.disable(); dbg.disable();
yargs(hideBin(process.argv)) yargs(hideBin(process.argv))
.version("1.0.0") .version(pkg.version)
.command( .command(
"compile <input>", "compile <input>",
"Compile source", "Compile source",

View File

@ -71,6 +71,7 @@ export class RustTarget extends CompileTarget<{ rust_crate: string }> {
a(0, `#[derive(Clone, Debug, Serialize, Deserialize)]`); a(0, `#[derive(Clone, Debug, Serialize, Deserialize)]`);
a(0, `pub struct ${definition.name} {`); a(0, `pub struct ${definition.name} {`);
for (const field of definition.fields) { for (const field of definition.fields) {
a(1, `#[allow(non_snake_case)]`);
if (field.array) { if (field.array) {
a(1, `pub ${field.name}: Vec<${toRustType(field.type)}>,`); a(1, `pub ${field.name}: Vec<${toRustType(field.type)}>,`);
} else if (field.map) { } else if (field.map) {
@ -142,6 +143,7 @@ export class RustTarget extends CompileTarget<{ rust_crate: string }> {
let ret = fnc.return let ret = fnc.return
? typeToRust(fnc.return.type, fnc.return.array) ? typeToRust(fnc.return.type, fnc.return.array)
: "()"; : "()";
a(1, `#[allow(non_snake_case)]`);
a(1, `pub async fn ${fnc.name}(&self, ${params}) -> Result<${ret}> {`); a(1, `pub async fn ${fnc.name}(&self, ${params}) -> Result<${ret}> {`);
a(2, `let l_req = JRPCRequest {`); a(2, `let l_req = JRPCRequest {`);
a(3, `jsonrpc: "2.0".to_owned(),`); a(3, `jsonrpc: "2.0".to_owned(),`);
@ -206,6 +208,7 @@ export class RustTarget extends CompileTarget<{ rust_crate: string }> {
let ret = fnc.return let ret = fnc.return
? typeToRust(fnc.return.type, fnc.return.array) ? typeToRust(fnc.return.type, fnc.return.array)
: "()"; : "()";
a(1, `#[allow(non_snake_case)]`);
a(1, `async fn ${fnc.name}(&self, ${params}) -> Result<${ret}>;`); a(1, `async fn ${fnc.name}(&self, ${params}) -> Result<${ret}>;`);
} }
a(0, `}`); a(0, `}`);
@ -235,6 +238,7 @@ export class RustTarget extends CompileTarget<{ rust_crate: string }> {
a(1, `fn get_id(&self) -> String { "${definition.name}".to_owned() }`); a(1, `fn get_id(&self) -> String { "${definition.name}".to_owned() }`);
a(0, ``); a(0, ``);
a(1, `#[allow(non_snake_case)]`);
a( a(
1, 1,
`async fn handle(&self, msg: &JRPCRequest, function: &str) -> Result<(bool, Value)> {` `async fn handle(&self, msg: &JRPCRequest, function: &str) -> Result<(bool, Value)> {`

View File

@ -12,5 +12,4 @@ serde_json = "1.0.88"
nanoid = "0.4.0" nanoid = "0.4.0"
tokio = { version = "1.22.0", features = ["full"] } tokio = { version = "1.22.0", features = ["full"] }
log = "0.4.17" log = "0.4.17"
simple_logger = { version = "4.0.0", features = ["threads", "colored", "timestamps", "stderr"] }
async-trait = "0.1.59" async-trait = "0.1.59"