pub fn server_macro_impl(
    args: TokenStream2,
    body: TokenStream2,
    server_context: Option<ServerContext>,
    server_fn_path: Option<Path>
) -> Result<TokenStream2>
Expand description

The implementation of the server_fn macro. To allow the macro to accept a custom context from the server, pass a custom server context to this function. The Context comes from the server. Optionally, the first argument of a server function can be a custom context. This context can be used to inject dependencies like the HTTP request or response or other server-only dependencies, but it does not have access to state that exists in the client.

The paths passed into this function are used in the generated code, so they must be in scope when the macro is called.

#[proc_macro_attribute]
pub fn server(args: proc_macro::TokenStream, s: TokenStream) -> TokenStream {
    let server_context = Some(ServerContext {
        ty: syn::parse_quote!(MyContext),
        path: syn::parse_quote!(my_crate::prelude::MyContext),
    });
    match server_macro_impl(
        args.into(),
        s.into(),
        Some(server_context),
        Some(syn::parse_quote!(my_crate::exports::server_fn)),
    ) {
        Err(e) => e.to_compile_error().into(),
        Ok(s) => s.to_token_stream().into(),
    }
}