You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/api_design.md
+13-16Lines changed: 13 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,21 +6,20 @@ See [`client`](crate::client) module for more details.
6
6
7
7
Key components for the client:
8
8
9
-
**ClientCallers**
9
+
**Connections Pool**:
10
10
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:
12
12
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`
15
15
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.
19
18
20
19
**Client**
21
20
22
21
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:
24
23
25
24
For example:
26
25
@@ -47,17 +46,16 @@ where
47
46
}
48
47
```
49
48
50
-
51
-
blocking-context is not implemented yet.
49
+
NOTE: blocking-context is not implemented yet.
52
50
53
51
### 2. Service
54
52
55
53
A Service in `razor-rpc` follows these principles:
56
54
- Called with immutable `&self` (server-side requires `Sync`)
57
55
- 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`
60
56
- 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).
61
59
62
60
We supports rust 1.75 `AFIT` (Async fn in Traits) `RPITIT` (Return Position Impl Trait in Traits), and legacy `#[async_trait]`.
63
61
@@ -100,7 +98,7 @@ There's slight cost to call method on trait object, but this is very trivial com
100
98
101
99
See [`server`](crate::server) module for more details.
Copy file name to clipboardExpand all lines: src/lib.rs
+3-2Lines changed: 3 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -12,8 +12,9 @@
12
12
//!
13
13
//! - Independent from async runtime (with plugins)
14
14
//! - 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
17
18
//! [RpcErrCodec](crate::error::RpcErrCodec))
18
19
//! - 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.
0 commit comments