Skip to main content

ClientConfig

Struct ClientConfig 

Source
pub struct ClientConfig {
Show 20 fields pub server_url: String, pub transport: TransportProtocol, pub transports: Option<Vec<TransportProtocol>>, pub protocol_urls: Option<HashMap<TransportProtocol, String>>, pub race_timeout: Option<Duration>, pub serialization_format: SerializationFormat, pub compression: CompressionAlgorithm, pub force_serialization_format: Option<SerializationFormat>, pub force_compression: Option<CompressionAlgorithm>, pub connect_timeout: Duration, pub reconnect_interval: Duration, pub max_reconnect_attempts: Option<u32>, pub heartbeat: HeartbeatConfig, pub tls: TlsConfig, pub connection_id: Option<String>, pub user_id: Option<String>, pub metadata: HashMap<String, String>, pub enable_router: bool, pub device_info: Option<DeviceInfo>, pub token: Option<String>,
}
Expand description

客户端配置

Fields§

§server_url: String

服务器地址(单个协议时使用,多协议时用作默认地址)

§transport: TransportProtocol

传输协议(单个)

§transports: Option<Vec<TransportProtocol>>

传输协议列表(用于竞速,如果设置了此列表,transport 将被忽略) 列表顺序就是优先级顺序,前面的优先级更高

§protocol_urls: Option<HashMap<TransportProtocol, String>>

每个协议的独立地址配置(协议 -> 地址映射) 如果设置了此映射,每个协议将使用对应的地址

§race_timeout: Option<Duration>

协议竞速超时时间(如果启用多协议竞速)

§serialization_format: SerializationFormat

序列化格式(首选格式,用于协商)

§compression: CompressionAlgorithm

压缩算法(首选算法,用于协商)

§force_serialization_format: Option<SerializationFormat>

强制指定的序列化格式(如果设置,则强制使用此格式,不进行协商) 适用于某些端不支持 protobuf 等格式的场景

§force_compression: Option<CompressionAlgorithm>

强制指定的压缩算法(如果设置,则强制使用此算法,不进行协商)

§connect_timeout: Duration

连接超时时间

§reconnect_interval: Duration

重连间隔

§max_reconnect_attempts: Option<u32>

最大重连次数(None 表示无限重连)

§heartbeat: HeartbeatConfig

心跳配置

§tls: TlsConfig

TLS 配置

§connection_id: Option<String>

自定义连接 ID(如果为 None,则自动生成)

§user_id: Option<String>

用户 ID(用于认证)

§metadata: HashMap<String, String>

额外的元数据

§enable_router: bool

是否启用消息路由(默认 false)

§device_info: Option<DeviceInfo>

设备信息(用于协商和设备管理)

§token: Option<String>

Token(用于认证,如果服务端启用认证,必须提供)

Implementations§

Source§

impl ClientConfig

Source

pub fn new(server_url: String) -> Self

创建新的客户端配置

Source

pub fn websocket(self) -> Self

使用 WebSocket 协议

Source

pub fn quic(self) -> Self

使用 QUIC 协议

Source

pub fn tcp(self) -> Self

使用 TCP 协议

Source

pub fn with_format(self, format: SerializationFormat) -> Self

设置序列化格式

Source

pub fn with_compression(self, compression: CompressionAlgorithm) -> Self

设置压缩算法

Source

pub fn with_user_id(self, user_id: String) -> Self

设置用户 ID

Source

pub fn with_token(self, token: String) -> Self

设置 Token(用于认证,如果服务端启用认证,必须提供)

Source

pub fn with_protocol_race(self, protocols: Vec<TransportProtocol>) -> Self

启用多协议竞速

协议列表的顺序就是优先级顺序,前面的协议优先级更高 例如:with_protocol_race(vec![QUIC, WebSocket]) 表示 QUIC 优先级高于 WebSocket

Source

pub fn with_protocol_url(self, protocol: TransportProtocol, url: String) -> Self

为特定协议设置服务器地址

Source

pub fn with_protocol_urls( self, urls: HashMap<TransportProtocol, String>, ) -> Self

批量设置协议地址映射

Source

pub fn get_protocol_url(&self, protocol: &TransportProtocol) -> String

获取指定协议的地址

Source

pub fn with_race_timeout(self, timeout: Duration) -> Self

设置竞速超时时间

Source

pub fn with_heartbeat(self, heartbeat: HeartbeatConfig) -> Self

设置心跳配置

Source

pub fn with_tls(self, tls: TlsConfig) -> Self

设置 TLS 配置

Source

pub fn with_connect_timeout(self, timeout: Duration) -> Self

设置连接超时

Source

pub fn with_reconnect_interval(self, interval: Duration) -> Self

设置重连间隔

Source

pub fn with_max_reconnect_attempts(self, max: Option<u32>) -> Self

设置最大重连次数(None 表示无限重连)

Source

pub fn enable_router(self) -> Self

启用消息路由

Source

pub fn with_device_info(self, device_info: DeviceInfo) -> Self

设置设备信息(用于协商和设备管理)

Source

pub fn force_format(self, format: SerializationFormat) -> Self

强制指定序列化格式(不进行协商,直接使用此格式)

适用于某些端不支持 protobuf 等格式的场景 如果设置了强制格式,客户端将直接使用此格式,服务端必须接受

Source

pub fn force_compression(self, compression: CompressionAlgorithm) -> Self

强制指定压缩算法(不进行协商,直接使用此算法)

如果设置了强制压缩,客户端将直接使用此算法,服务端必须接受

Source

pub fn is_force_format(&self) -> bool

检查是否强制指定了格式(不进行协商)

Source

pub fn get_serialization_format(&self) -> SerializationFormat

获取实际使用的序列化格式(强制格式优先,否则使用首选格式)

Source

pub fn get_compression(&self) -> CompressionAlgorithm

获取实际使用的压缩算法(强制算法优先,否则使用首选算法)

Source

pub fn get_protocols(&self) -> Vec<TransportProtocol>

获取要使用的协议列表

Source

pub fn is_race_mode(&self) -> bool

是否启用协议竞速

Trait Implementations§

Source§

impl Clone for ClientConfig

Source§

fn clone(&self) -> ClientConfig

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ClientConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ClientConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for ClientConfig

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for ClientConfig

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more