You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Maybe a little, but main point is it's way more convinient to use. Let's say we want to encode ComplexStruct
structSimpleStruct{a:u32,b:String,}enumMultiEnum{VariantA(i32),VariantB(String),VariantC{x:u8,y:f64},UnitVariant,// Unit variant added}structUnitStruct;structNewtypeStruct(i32);structTupleStruct(i32,f64,String);structComplexStruct{flag:bool,inner:SimpleStruct,items:Vec<MultiEnum>,unit:UnitStruct,newtype:NewtypeStruct,tuple:TupleStruct,map:HashMap<i32,i64>}
from Rust to TypeScript.
With #46, we can do it like this:
import*asRegistryfrom"./bincode/registry.ts"// generated fileconstComplexStruct_obj: Registry.ComplexStruct={// using it as Typeinner: {a: 42,b: "Hello"},flag: true,items: [{$: "VariantA",VariantA: 10},{$: "VariantB",VariantB: "World"}],unit: null,newtype: 99,tuple: [123,45.67,"Test"],map: newMap().set(3,7n)}constencoded=Registry.ComplexStruct.encode(ComplexStruct_obj)// using object CompexStruct
We can also in some code use only type imports: import { type ComplexStruct } from "./bincode/registry.ts"
This is way more convinient than writing new ComplexStruct(..., new MultiEnumVariantC(... new X(..., new Y(), ...)), ...) and so on.
I believe output like with ts-proto when it's possible to encode plain objects would be much beter then using classes:
output ts:
The text was updated successfully, but these errors were encountered: