#procedural macro for generating types

14 messages · Page 1 of 1 (latest)

quasi nest
#

I would like a way to have a procedural macro, above my api endpoint handler functions that would specify the route, args, etc. and they would be put into one function in main.rs for the actual warp routes. i also would like it to beable to go to build.rs so i can have a mapped-type for typescript so i can have type checking on arguments to my backend api.
eg:
endpoints.rs

#[endpoint(get, "/admin/login", DB, JSON)]
pub fn admin_login_handler(db:DB, data:frontend::AdminLogin)...

#[endpoint(get, ("/admin/query", u32), DB, JSON)]
pub fn admin_query_handler(q:u32, db:DB, data:frontend::AdminLogin)...

main.rs

fn main() {
  let routes = get_routes!(db);
  warp::serve(routes)...
}

build.rs

fn main() {
  let txt = ts::export::<TYPES(&Default::default());
  txt.append(get_route_types!());
  save file
}

is this possible?

pine dock
#

?crate linkme

candid lodgeBOT
#

Safe cross-platform linker shenanigans

Version

0.3.31

Downloads

3 502 785

pine dock
#

?crate inventory

candid lodgeBOT
#

Typed distributed plugin registration

Version

0.3.17

Downloads

23 691 874

pine dock
#

for the second one, check out ts-rs

#

?crate ts-rs

candid lodgeBOT
#

generate typescript bindings from rust types

Version

10.1.0

Downloads

1 068 831

quasi nest
#

one thing about ts-rs, is that it puts all types in different files. which isn't a totally bad thing.
I would just prefer it to be one. and i'm not sure how ts-rs would generate a typescript string

type RequestTypes = {
  '/admin/login' = AdminLogin,
  '/admin/query' = null //(above i had AdminLogin, that is wrong)
}

let alone, from a attribute macro that doesn't exist.

I am also confused about linkme and inventory. i'm not sure how those would come into play.

quasi nest
#

my goal is to not have 3 different places, where i need to change so one thing will work.
i just want to have a simple attribute nexto the handler function,
it will somehow save the name of the handler and the warp filter options.
in the main function, it can just make a call and get the tree from those attributes. same in the builds.rs, just with arg types instead.

pine dock
#

as the "somehow save"

quasi nest
#

ok,