teamplayer3 / postcard-bindgen Goto Github PK
View Code? Open in Web Editor NEWA crate which generates bindings for the postcard binary format for other languages than Rust.
License: Apache License 2.0
A crate which generates bindings for the postcard binary format for other languages than Rust.
License: Apache License 2.0
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
postcard-bindgen-core/Cargo.toml
genco 0.17.8
convert_case 0.6.0
heapless 0.8.0
postcard-bindgen-derive/Cargo.toml
quote 1.0.35
serde_derive_internals 0.29
syn 2.0.50
serde 1
proc-macro2 1.0
genco 0.17.8
convert_case 0.6.0
regex 1.10.3
regex-macro 0.2.0
postcard-bindgen/Cargo.toml
postcard 1.0.8
serde 1.0
.github/workflows/rust.yml
actions/checkout v4
actions/checkout v4
Swatinem/rust-cache v2
actions/checkout v4
Swatinem/rust-cache v2
actions/checkout v4
Swatinem/rust-cache v2
postcard-bindgen/test-bindings-proj/package.json
tslint ^6.1.3
typescript ^5.0.0
@types/node ^20.0.0
enum A {
B(u8)
}
->
{
key: "B",
value: 12323
}
current:
{
key: "B",
value: [ 12323 ]
}
I've noticed serialize format checking for a float field runs !Number.isInteger()
on the value, but that that doesn't quite work correctly. Numbers like 1.0 will return true, causing encoding to fail. I wonder if that check should be removed entirely and just leave the check for the number type. It isn't really a problem to have an integer in a float field. The problem would be if we tried to pass a float in an integer field.
First, nice project, and thanks for producing it.
Would the following be easy to support? Or is there another way to go about it?
#[derive(Serialize, PostcardBindings)]
struct Test {
name: u8,
other: u16,
values: [u32; 32],
}
10 | values: [u32; 32],
| ^^^^^^^^^ the trait `GenJsBinding` is not implemented for `[u32; 32]
heapless::Vec support appears to be included when you enable the heapless feature, but I'm still having trouble with it.
impl<T: GenJsBinding, const N: usize> GenJsBinding for heapless::Vec<T, N> {
fn get_type() -> JsType {
JsType::Array(ArrayMeta {
items_type: Box::new(T::get_type()),
})
}
}
When I try to compile generate_bindings!(heapless::Vec<EncoderReading, 10>)
I get
error[E0277]: the trait bound `heapless::Vec<EncoderReading, 10>: JsBindings` is not satisfied
--> js-bindings/src/main.rs:10:28
|
10 | generate_bindings!(heapless::Vec<common_structs::EncoderReading, 10>),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `JsBindings` is not implemented for `heapless::Vec<EncoderReading, 10>`
|
= help: the trait `JsBindings` is implemented for `EncoderReading`
Is there something I'm doing wrong here?
Use the first enum style like in this wasm proposal.
type MyEnum =
| { tag: 'A' }
| { tag: 'B', value: number }
| { tag: 'C', value: [number, number] }
| { tag: 'D', value: { x: number, y: number }
;
It allows writing switch cases:
switch (enum.tag) {
case 'A': ...; break;
case 'B': ....
}
UnitType in rust:
struct T;
Problem with typescript: microsoft/TypeScript#47486
-> empty interfaces match to any type -> mostly not allowed with eslint
Not working ts decl:
export type T = {}
declare function test_func(t: T): void
test_func([23]) // no error
Use structure types as in rust structures.
NewType as in new type idiom.
Match to serde ast style
// unit struct -> Style::Unit
struct A;
// new type struct -> Style::Newtype
struct B(u8);
// tuple struct -> Style::Tuple
struct C(u8, u16);
// struct (c-like) -> Style::Struct
struct D {
a: u8,
b: u16,
}
// enum
enum E {
A, // unit struct -> unit variant -> Style::Unit
B(u8), // new type struct/ tuple struct -> new type variant -> Style::Newtype
C(u8, u16), // tuple struct -> tple variant -> Style::Tuple
D { // struct (c-like) -> struct variant -> Style::Struct
a: u8,
b: u16
}
}
Maybe isolated.
Tried with the basic Test example of the readme, js output is fine until the end of serializer class, then a few \n
/;
are missing.
*.d.ts file do not contains any line separator.
Any idea where it might come from?
// Previous code is fine
const serialize_FOO = (s, v) => {
s.serialize_number(U8_BYTES, false, v.name);
s.serialize_number(U16_BYTES, false, v.other)
} const deserialize_FOO = (d) => ({ name: d.deserialize_number(U8_BYTES, false), other: d.deserialize_number(U16_BYTES, false) }) const is_FOO = (v) => (typeof v === "object" && typeof v.name === "number" && typeof v.other === "number") module.exports.serialize = (type, value) => {
if (!(typeof type === "string")) { throw "type must be a string" } const s = new Serializer() switch (type) {
case "FOO": if (is_FOO(value)) { serialize_FOO(s, value) } else throw "value has wrong format";
break
} return s.finish()
} module.exports.deserialize = (type, bytes) => { if (!(typeof type === "string")) { throw "type must be a string" } const d = new Deserializer(bytes) switch (type) { case "FOO": return deserialize_FOO(d) } }
Everything works fine once linebreak are added manually.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.