Expand description
§RPC 工具和结构体
这个模块包含了一些用于处理RPC(远程过程调用)的实用工具和结构体。
它使用了多个库,包括anyhow
、flume
、futures-lite
、futures-util
、quic_rpc
、tokio
和tracing
。
§主要组件和功能
- 导入和重导出:使用
pub use
语句重导出了一些库中的类型和函数,以便在其他模块中直接使用。 GetServiceHandler
trait:定义了一个trait,用于获取特定服务的处理程序。ServiceHandler
trait:定义了一个trait,用于服务的处理程序。run_server
函数:用于运行一个RPC服务器。ClientStreamingResponse
结构体:用于处理客户端流式RPC响应。ServerStreamingResponse
结构体:用于处理服务器流式RPC响应。
§注意事项
- 异步处理:代码中大量使用了异步处理,包括
async/await
关键字和Future
trait。 - 错误处理:代码中使用了
Result
和Error
类型进行错误处理。 - 并发:代码中使用了
Arc
和LazyLock
来处理并发访问和延迟初始化。 - 类型安全:通过trait和泛型,代码确保了类型安全。
§用途
这个模块给微服务框架导出了一些工具函数和结构体,可以处理不同类型的RPC请求,包括客户端流式和服务器流式请求。 它提供了基本的错误处理和并发支持,使得开发者可以更容易地构建高性能的RPC服务。
Macros§
- Pins a value on the stack.
Structs§
- Bidirectional streaming interaction pattern
- Client streaming interaction pattern
- The
Error
type, a wrapper around a dynamic error type. - A channel for requests and responses for a specific service.
- A client for a specific service
- A server for a specific service.
- The Tokio runtime.
- Server streaming interaction pattern
- Sink that can be used to send updates to the server for the two interaction patterns that support it, crate::message::ClientStreaming and crate::message::BidiStreaming.
Enums§
- Server error when accepting a bidi request
- Server error when receiving an item for a bidi request
- Server error when accepting a client streaming request
- Server error when receiving an item for a client streaming request
- Client error. All client DSL methods return a
Result
with this error type. - Server error when accepting a server streaming request
- Client error when handling responses from a server streaming request
Traits§
- Defines update type and response type for a bidi streaming message.
- Stream types on the server side
- Defines update type and response type for a client streaming message.
- A connector to a specific service
- 获取特定服务的处理程序
- A listener for a specific service
- Declares the interaction pattern for a message and a service.
- Requirements for a RPC message
- Defines the response type for a rpc message.
- Defines response type for a server streaming message.
- A service
- 服务的处理程序
- A stream of values produced asynchronously.
- Extension trait for
Stream
.
Functions§
- Create a channel with a maximum capacity.
- Creates a new one-shot channel for sending single values across asynchronous tasks.
Type Aliases§
- Sync version of
future::stream::BoxStream
. - Type alias for when you want to require a boxed channel
- Type alias for a boxed connection to a specific service
- Type alias for a service endpoint
Result<T, Error>