rust2.0 #1

Merged
hibas123 merged 13 commits from rust2.0 into main 2024-08-13 10:00:18 +00:00
4 changed files with 8 additions and 3 deletions
Showing only changes of commit a291851b5a - Show all commits

View File

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

View File

@ -4,13 +4,15 @@ import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import startCompile, { Target, Targets } from "./process";
const pkg = require("../package.json");
import dbg from "debug";
const log = dbg("app");
dbg.disable();
yargs(hideBin(process.argv))
.version("1.0.0")
.version(pkg.version)
.command(
"compile <input>",
"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, `pub struct ${definition.name} {`);
for (const field of definition.fields) {
a(1, `#[allow(non_snake_case)]`);
if (field.array) {
a(1, `pub ${field.name}: Vec<${toRustType(field.type)}>,`);
} else if (field.map) {
@ -142,6 +143,7 @@ export class RustTarget extends CompileTarget<{ rust_crate: string }> {
let ret = fnc.return
? 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(2, `let l_req = JRPCRequest {`);
a(3, `jsonrpc: "2.0".to_owned(),`);
@ -206,6 +208,7 @@ export class RustTarget extends CompileTarget<{ rust_crate: string }> {
let ret = fnc.return
? typeToRust(fnc.return.type, fnc.return.array)
: "()";
a(1, `#[allow(non_snake_case)]`);
a(1, `async fn ${fnc.name}(&self, ${params}) -> Result<${ret}>;`);
}
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(0, ``);
a(1, `#[allow(non_snake_case)]`);
a(
1,
`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"
tokio = { version = "1.22.0", features = ["full"] }
log = "0.4.17"
simple_logger = { version = "4.0.0", features = ["threads", "colored", "timestamps", "stderr"] }
async-trait = "0.1.59"