When I try to make a WIT variant
from Rust using serde_json
from an enum
using serde's "adjacently tagged", the tag
value is capitalized.
But in jco
the tag
values are all lowercase.... meaning the switch cases won't match.
// from Rust we get Capitalized:
{ tag: "Enumfromrust", val: "some string...."}
// jco expect wit lowercase:
{ tag: "enumfromrust", val: "some string...."}
Anyone know of a straightforward way to convert between the two?
Example of Uppercase serialised enum:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=a4673792be008cb23d4533da42f8cabc
Serde adj tags: https://serde.rs/enum-representations.html#adjacently-tagged
I wonder if it would be worth updating the output in Rust to use kebab-case enum tags?
in JS at least, that is the toolchain convention and per WIT semantics, toolchain-specific casing is used where appropriate
true, but my issue is mostly about that first Letter being Caps
I haven't found an elegant solution to make those leading letter lowercase in Rust yet, using serde anyway
The only serde.rs conversion I've found (builtin, so far) is camelCase
https://serde.rs/attr-rename.html
the rename_all
should support kebab-case
Yep you're right https://serde.rs/container-attrs.html#rename_all
AHH! There's lowercase:
The possible values are "lowercase", "UPPERCASE", "PascalCase", "camelCase", "snake_case", "SCREAMING_SNAKE_CASE", "kebab-case", "SCREAMING-KEBAB-CASE".
but good point about lowercase kebab, feels verrrry ...wit
ty.
Works like a charm, thanks @Guy Bedford !
DougAnderson444 | PeerPiper.io has marked this topic as resolved.
Geoff Goodman has marked this topic as unresolved.
Last updated: Dec 23 2024 at 13:07 UTC