convex-macros
Macros to help make Convex in Rust nice
Installation
[]
= "0.0.2"
# Required by code this macro generates.
= "1.0.80"
= "0.6.0"
= "1.0.185"
= "1.0"
Usage
Create models using the same Convex validator syntax as your schema definition.
convex_model!;
This generates pub struct User {}
with various methods to convert from convex::Value
and to serde_json::Value
.
let user = from_convex_value
.expect;
assert_eq!;
assert_eq!;
assert_eq!;
Features
let user = User::from_convex_value(value)?;
to parse a value from Convex clientjson!(user)
to serialize as json- Discriminated unions are automatically handled
- Helper functions for each branch are also exposed:
user.platform.as_2()?.username
Limitations
- This is experimental and may not be "production quality", use with caution.
v.bytes()
,v.array()
,v.any()
are not yet supported.- Field names must be valid Rust identifiers, so keywords like
type
cannot be a field name. Map it to_type
,kind
,t
, etc. - Union variant names are always named like:
Variant1
,Variant2
, etc. - The first acceptable union branch will be used if there are multiples that could validly parse data.
- This package generates code that expects
anyhow
,convex
,serde
, andserde_json
to be available.
License
MIT