Skip to content

Commit 55a06e9

Browse files
committed
Refine doc
1 parent 958db9e commit 55a06e9

2 files changed

Lines changed: 16 additions & 18 deletions

File tree

docs/api_design.md

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,20 @@ See [`client`](crate::client) module for more details.
66

77
Key components for the client:
88

9-
**ClientCallers**
9+
**Connections Pool**:
1010

11-
The following structs impl both [ClientCaller](crate::client::ClientCaller) (async) and [ClientCallerBlocking](crate::client::ClientCallerBlocking).
11+
The following are type alias from `razor-stream` crate:
1212

13-
- **[`ConnPool`](crate::client::ConnPool)**: Maintains a pool of worker connections
14-
- **[`FailoverPool`](crate::client::FailoverPool)**: Load balancing and failover, maintains multiple `ConnPool`
13+
- [`APIConnPool`](crate::client::APIConnPool): Maintains a pool of worker connections
14+
- [`APIFailoverPool`](crate::client::APIFailoverPool): Load balancing and failover, maintains multiple `ConnPool`
1515

16-
**APIClientCaller**
17-
18-
- **[`APIClientCaller`](crate::client::APIClientCaller)**: This trait defines `async fn call` - implemented directly on `ConnPool` and `FailoverPool`
16+
We have added a helper trait [`APIClientCaller`](crate::client::APIClientCaller), which defines a helper function for a service.method call.
17+
This trait is used in proc-macro `#[endpoint_async]` generated code for a service trait.
1918

2019
**Client**
2120

2221
Because client should defined by user to add their service method, we provide macro
23-
**[`endpoint_client!`](crate::client::endpoint_client)** to generates a client struct with generic, which have a new() method to wrap an APIClientCaller:
22+
**[`endpoint_client!`](crate::client::endpoint_client)** to generates a wraper struct with generic over the `APIClientCaller` connection pools, which have a new() method:
2423

2524
For example:
2625

@@ -47,17 +46,16 @@ where
4746
}
4847
```
4948

50-
51-
blocking-context is not implemented yet.
49+
NOTE: blocking-context is not implemented yet.
5250

5351
### 2. Service
5452

5553
A Service in `razor-rpc` follows these principles:
5654
- Called with immutable `&self` (server-side requires `Sync`)
5755
- Client and server share the same trait definition for compile-time checks
58-
- Service methods return `Result<T, RpcError<E>>` where `E: RpcErrCodec`
59-
- Methods should be `async fn` or return `impl Future`
6056
- Compatible with GRPC naming conventions (`service` in PascalCase, `method` in snake_case)
57+
- Methods should be `async fn` or return `impl Future`
58+
- Methods can return **custom error type**. All method should return `Result<T, RpcError<E>>` where `E: RpcErrCodec`, refer to doc: [error module](crate::error).
6159

6260
We supports rust 1.75 `AFIT` (Async fn in Traits) `RPITIT` (Return Position Impl Trait in Traits), and legacy `#[async_trait]`.
6361

@@ -100,7 +98,7 @@ There's slight cost to call method on trait object, but this is very trivial com
10098

10199
See [`server`](crate::server) module for more details.
102100

103-
## Example Usage
101+
## Example Usage (using ConnPool)
104102

105103
Steps:
106104

@@ -198,10 +196,9 @@ async fn use_client(server_addr: &str) {
198196
let mut client_config = ClientConfig::default();
199197
client_config.task_timeout = 5;
200198
let rt = RT::new_multi_thread(8);
201-
let client_facts = APIFact::<Codec>::new(client_config);
199+
let factory = APIFact::<Codec>::new(client_config);
202200
// 9. Create client connection pool
203-
let pool: APIConnPool<Codec, ClientProto> =
204-
client_facts.new_conn_pool::<ClientProto, RT>(&rt, server_addr);
201+
let pool: APIConnPool<Codec, ClientProto> = factory.new_conn_pool::<ClientProto, RT>(&rt, server_addr);
205202
let client = CalculatorClient::new(pool);
206203
// You will have to import CalculatorService trait to call its methods
207204
use CalculatorService;

src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
//!
1313
//! - Independent from async runtime (with plugins)
1414
//! - With service trait very similar to grpc / tarpc (stream in API interface is not supported currently)
15-
//! - Support latest `impl Future` definition of rust since 1.75, also support legacy `async_trait` wrapper
16-
//! - Each method can have different custom error type (requires the type implements
15+
//! - Support rust 1.75 `AFIT` (Async fn in Traits) `RPITIT` (Return Position Impl Trait in Traits),
16+
//! - Support traits wrapped with `#[async_trait::async_trait]` (Box dyn dispatch).
17+
//! - Each method can have **different custom error type** (requires the type implements
1718
//! [RpcErrCodec](crate::error::RpcErrCodec))
1819
//! - based on [razor-stream](https://docs.rs/razor-stream): Full duplex in each connection, with sliding window threshold, allow maximizing throughput and lower cpu usage.
1920
//!

0 commit comments

Comments
 (0)