stein-defs
v0.0.0-alpha.4
Published
`stein-defs` is a method for define object interfaces and compiling to `typescript`, `rust` and `go` source code. This allows you to define once and reuse across projects encompassing multiple languages
Downloads
4
Readme
Stein Defs
stein-defs
is a method for define object interfaces and compiling to typescript
, rust
and go
source code. This allows you to define once and reuse across projects encompassing multiple languages
Installation
npm install stein-defs
Usage
Define a .stein
file to contain your types. e.g.
message Person {
name: string
age: u32
height: f32
}
Define a steinrc.js
to configure the input and outputs
const path = require("path");
export default {
input: path.join(__dirname, "./examples"),
lang: {
go: {
out: path.join(__dirname, "./gen/go"),
header: "package main",
},
rust: {
out: path.join(__dirname, "./gen/rust"),
header: "mod main",
},
ts: {
out: path.join(__dirname, "./gen/ts"),
header: "",
},
},
};
Then run stein
to produce go
, rust
and typescript
file
go
package main
type Person struct {
Name string `json:"name"`
Age uint32 `json:"age"`
Height float32 `json:"height"`
}
rust
use serde::{Deserialize, Serialize, Debug}
mod main
#[derive(Serialize, Deserialize, Debug)]
struct Person {
name: String,
age: u32,
height: f32,
}
typescript
export interface Person {
name: string
age: number
height: number
}
Basic Types
| stein | typescript | rust | go | |---|---|---|---| | f32 | number | f32 | float32 | | i32 | number | i32 | int32 | | u32 | number | u32 | uint32 | | string | string | String | string | Map<Key, Value> | Map<Key, Value> | Map<Key, Value> | map[Key]Value | Value[] | Value[] | Vec | []Value