4 releases

0.1.3 Dec 20, 2022
0.1.2 Dec 10, 2022
0.1.1 Nov 23, 2022
0.1.0 Nov 22, 2022

#698 in Procedural macros

MIT license

40KB
601 lines

What is this

This is a macro for RPC programming needs which generates a structure and a thunk for function in a way that allows calling that function with a struct argument that supports serde::Deserialize

How to use

  1. Mark function with #[server_function] attribute

    #[server_function]
    fn add(a: u32, b: u32) -> u32 {
        a + b
    }
    
  2. This will generate AddArgs struct matching your function arguments that looks like this

    struct AddArgs {
        a: u32,
        b: u32
    }
    

    and a function named add_thunk with AddArgs struct as 1 argument

  3. Now you can call it

    // will return 10, same as original function
    add_thunk(AddArgs { a: 5, b: 5 })
    

Features

messagepack

Enables rmp-serde and allows server function to be called using raw messagepack bytes using with_bytes_thunk(bytes: &[u8])

Example

let bytes = rmp_serde::to_vec(AddArgs { a: 5, b: 5 }).unwrap();
add_messagepack_thunk(&bytes) // should return 10

Dependencies

~1–1.7MB
~34K SLoC