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§
- pin
- Pins a value on the stack.
Structs§
- Bidi
Streaming - Bidirectional streaming interaction pattern
- Client
Streaming - Client streaming interaction pattern
- Client
Streaming Response - Error
- The
Error
type, a wrapper around a dynamic error type. - RpcChannel
- A channel for requests and responses for a specific service.
- RpcClient
- A client for a specific service
- RpcServer
- A server for a specific service.
- Runtime
- The Tokio runtime.
- Server
Streaming - Server streaming interaction pattern
- Server
Streaming Response - Update
Sink - 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§
- Bidi
Streaming Error - Server error when accepting a bidi request
- Bidi
Streaming Item Error - Server error when receiving an item for a bidi request
- Client
Streaming Error - Server error when accepting a client streaming request
- Client
Streaming Item Error - Server error when receiving an item for a client streaming request
- RpcError
- Client error. All client DSL methods return a
Result
with this error type. - Server
Streaming Error - Server error when accepting a server streaming request
- Server
Streaming Item Error - Client error when handling responses from a server streaming request
Statics§
Traits§
- Bidi
Streaming Msg - Defines update type and response type for a bidi streaming message.
- Channel
Types - Stream types on the server side
- Client
Streaming Msg - Defines update type and response type for a client streaming message.
- Connection
Errors - Errors that can happen when creating and using a
Connector
orListener
. - Connector
- A connector to a specific service
- GetService
Handler - 获取特定服务的处理程序
- Listener
- A listener for a specific service
- Msg
- Declares the interaction pattern for a message and a service.
- RpcMessage
- Requirements for a RPC message
- RpcMsg
- Defines the response type for a rpc message.
- Server
Streaming Msg - Defines response type for a server streaming message.
- Service
- A service
- Service
Handler - 服务的处理程序
- Stream
- A stream of values produced asynchronously.
- Stream
Ext - Extension trait for
Stream
.
Functions§
- flume_
bounded - Create a channel with a maximum capacity.
- oneshot_
channel - Creates a new one-shot channel for sending single values across asynchronous tasks.
- run_
server
Type Aliases§
- BoxStream
Sync - Sync version of
future::stream::BoxStream
. - Boxed
Channel Types - Type alias for when you want to require a boxed channel
- Boxed
Connector - A boxed connector for the given
Service
- Boxed
Listener - A boxed listener for the given
Service
- Result
Result<T, Error>