Rust Macro: convex_model!
I've been using the Convex Rust client and found working with nested objects a bit cumbersome. I made a macro that creates native Rust structs and enums based on a Typescript schema definition. Then you can build it from
convex::Value and serialize it to serde_json::Value automatically.This generates
pub struct User {} with various methods to convert from convex::Value and to serde_json::Value.Some Features:
-
let user = User::from_convex_value(value)?; to parse a value from Convex client.-
json!(user) to serialize as json.- Discriminated unions are automatically handled.
- Helper functions for each union branch:
user.platform.as_2()?.username.