Skip to main content

Crate netxbuilder

Crate netxbuilder 

Source
Expand description

§netxbuilder — proc-macro code generation for the netx RPC framework

This crate provides four proc-macro attributes:

AttributeWhere usedPurpose
#[build_client]traitGenerate client proxy struct + optional dispatcher
#[build_server]traitGenerate server-push proxy + optional dispatcher
#[build_impl]impl blockMarker (no-op); validates the impl block parses
#[build_impl_client]impl blockSame as above + adds #[async_trait::async_trait]
#[tag(N)]trait methodAssigns a command ID; consumed by the above macros

§How it all fits together

 User writes:

  #[build_client(ClientController)]   ← "I am the server; clients implement this"
  pub trait IClientController {
      #[tag(2001)]
      async fn on_message(&self, from: String, text: String);   // tt=0: fire-and-forget
      #[tag(2002)]
      async fn on_ping(&self, t: i64) -> Result<i64>;           // tt=2: returns a value
  }

 Macro generates:
  1. The trait itself (with #[async_trait])
  2. impl IController for ClientController { fn call(...) { match cmd_tag { ... } } }
     — deserialises arguments and dispatches to the correct method
  3. pub struct ___impl_IClientController_call<T> { client: T }
     — a proxy struct that can be used as `impl IClientController`

Attribute Macros§

build_client
Generate the client-side interface infrastructure from a trait definition.
build_impl
Marker attribute for server-side impl blocks.
build_impl_client
Marker attribute for client-side impl blocks.
build_server
Generate the server-side push interface from a trait definition.
tag
Pass-through attribute that assigns a command ID to a trait method.