ash_rpc_core/lib.rs
1//! # ash-rpc-core
2//!
3//! A comprehensive JSON-RPC 2.0 implementation with transport support.
4//!
5//! ## Features
6//!
7//! - **Complete JSON-RPC 2.0 support** - Request, response, notification, and batch handling
8//! - **Multiple transports** - TCP, TCP streaming, HTTP via Axum, and Tower middleware
9//! - **Type-safe builders** - Fluent API for constructing requests and responses
10//! - **Method registry** - Organize and dispatch JSON-RPC methods
11//! - **Auto-documentation** - Generate OpenAPI/Swagger specs from method definitions
12//! - **Macro support** - Convenient macros for common response patterns
13//!
14//! ## Quick Start
15//!
16//! ```rust,no_run
17//! use ash_rpc_core::*;
18//! use serde_json::Value;
19//!
20//! // Create a method registry
21//! let registry = MethodRegistry::new()
22//! .register("ping", |_params, id| {
23//! rpc_success!("pong", id)
24//! })
25//! .register("add", |params, id| {
26//! if let Some(params) = params {
27//! let nums: Vec<i32> = serde_json::from_value(params).unwrap();
28//! if nums.len() == 2 {
29//! rpc_success!(nums[0] + nums[1], id)
30//! } else {
31//! rpc_error!(error_codes::INVALID_PARAMS, "Expected 2 numbers", id)
32//! }
33//! } else {
34//! rpc_error!(error_codes::INVALID_PARAMS, "Parameters required", id)
35//! }
36//! });
37//!
38//! // Call a method
39//! let response = registry.call("ping", None, Some(Value::Number(serde_json::Number::from(1))));
40//! ```
41
42// Module declarations
43pub mod builders;
44pub mod macros;
45pub mod registry;
46pub mod traits;
47pub mod transport;
48pub mod types;
49pub mod utils;
50
51#[cfg(feature = "tower")]
52pub mod middleware;
53
54// Re-export tokio for tcp-stream feature
55#[cfg(feature = "tcp-stream")]
56pub use tokio;
57
58// Re-export tower for tower feature
59#[cfg(feature = "tower")]
60pub use tower;
61
62// Re-export all core types
63pub use types::*;
64
65// Re-export all builders
66pub use builders::*;
67
68// Re-export all traits
69pub use traits::*;
70
71// Re-export registry
72pub use registry::*;
73
74// Re-export transport functionality
75pub use transport::*;
76
77// Re-export middleware when tower feature is enabled
78#[cfg(feature = "tower")]
79pub use middleware::*;