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
It'd be nice to have support for custom structured arguments, since Field::Struct exists.
Original idea
This will be split into two derive macros:
TryFromField to support new types as parameters
TryIntoField to support new types as return types
Will also require changes to the job macro.
Examples
As a parameter:
use gadget_blueprint_proc_macro::TryFromField;// Implements TryFrom<Field<AccountId32>> for `MulArgs`#[derive(TryFromField)]structMulArgs{a:u32,b:u32,}#[job(id = 0, params(args),/* ... */)]pubfnmul(args:MulArgs,context:MyContext) -> Result<u32, gadget_sdk::Error>{Ok(args.a.saturating_mul(args.b))}
As a return type:
use gadget_blueprint_proc_macro::TryIntoField;// Implements TryFrom<BundledArgs> for `Field<AccountId32>`#[derive(TryIntoField)]structBundledArgs{a:u32,b:u32,c:u32,}#[job(id = 0, params(a, b, c),/* ... */)]pubfnbundle(a:u32,b:u32,c:u32,context:MyContext) -> Result<BundledArgs, gadget_sdk::Error>{Ok(BundledArgs{
a,
b,
c,})}
We can have a blueprint-serde crate that converts to and from the Field type.
Examples
use serde::{Serialize,Deserialize};#[derive(Serialize,Deserialize)]structPerson{name:String,age:u8,}fnmain(){let person = Person{name:String::from("John"),age:40,};let field = gadget_blueprint_serde::to_field(&person).unwrap();assert_eq!(field,Field::Struct(BoundedString("Person"),Box(BoundedVec((BoundedString("name"),Field::String(BoundedString(&self.name)),),(BoundedString("age"),Field::Uint8(self.age)),)),));let person:Person = gadget_blueprint_serde::from_field(&field).unwrap();assert_eq!(person,Person{name:String::from("John"),age:40});}
The text was updated successfully, but these errors were encountered:
Will this design work with Nested structs? what about remote types? is it possible to leverage serde instead of our custom macros? i.e create serde_blueprint::to_fileds and serde_blueprint::from_fields such that we can use it with anything that implements serde traits?
Overview
It'd be nice to have support for custom structured arguments, since
Field::Struct
exists.Original idea
This will be split into two derive macros:
TryFromField
to support new types as parametersTryIntoField
to support new types as return typesWill also require changes to the
job
macro.Examples
As a parameter:
As a return type:
We can have a
blueprint-serde
crate that converts to and from theField
type.Examples
The text was updated successfully, but these errors were encountered: