pub struct WireframeClientBuilder<S = BincodeSerializer, P = ()> { /* private fields */ }Expand description
Builder for WireframeClient.
§Examples
use wireframe::client::WireframeClientBuilder;
let builder = WireframeClientBuilder::new();
let _ = builder;Implementations§
Source§impl<S, P> WireframeClientBuilder<S, P>
impl<S, P> WireframeClientBuilder<S, P>
Sourcepub fn serializer<Ser>(self, serializer: Ser) -> WireframeClientBuilder<Ser, P>
pub fn serializer<Ser>(self, serializer: Ser) -> WireframeClientBuilder<Ser, P>
Replace the serializer used for encoding and decoding messages.
§Examples
use wireframe::{BincodeSerializer, client::WireframeClientBuilder};
let builder = WireframeClientBuilder::new().serializer(BincodeSerializer);
let _ = builder;Sourcepub fn codec_config(self, codec_config: ClientCodecConfig) -> Self
pub fn codec_config(self, codec_config: ClientCodecConfig) -> Self
Configure codec settings for the connection.
§Examples
use wireframe::client::{ClientCodecConfig, WireframeClientBuilder};
let codec = ClientCodecConfig::default().max_frame_length(2048);
let builder = WireframeClientBuilder::new().codec_config(codec);
let _ = builder;Sourcepub fn max_frame_length(self, max_frame_length: usize) -> Self
pub fn max_frame_length(self, max_frame_length: usize) -> Self
Configure the maximum frame length for the connection.
§Examples
use wireframe::client::WireframeClientBuilder;
let builder = WireframeClientBuilder::new().max_frame_length(2048);
let _ = builder;Sourcepub fn length_format(self, length_format: LengthFormat) -> Self
pub fn length_format(self, length_format: LengthFormat) -> Self
Configure the length prefix format for the connection.
§Examples
use wireframe::{client::WireframeClientBuilder, frame::LengthFormat};
let builder = WireframeClientBuilder::new().length_format(LengthFormat::u16_be());
let _ = builder;Sourcepub fn socket_options(self, socket_options: SocketOptions) -> Self
pub fn socket_options(self, socket_options: SocketOptions) -> Self
Replace the socket options applied before connecting.
§Examples
use wireframe::client::{SocketOptions, WireframeClientBuilder};
let options = SocketOptions::default().nodelay(true);
let builder = WireframeClientBuilder::new().socket_options(options);
let _ = builder;Sourcepub fn nodelay(self, enabled: bool) -> Self
pub fn nodelay(self, enabled: bool) -> Self
Configure TCP_NODELAY for the connection.
§Examples
use wireframe::client::WireframeClientBuilder;
let builder = WireframeClientBuilder::new().nodelay(true);
let _ = builder;Sourcepub fn keepalive(self, duration: Option<Duration>) -> Self
pub fn keepalive(self, duration: Option<Duration>) -> Self
Configure SO_KEEPALIVE for the connection.
§Examples
use std::time::Duration;
use wireframe::client::WireframeClientBuilder;
let builder = WireframeClientBuilder::new().keepalive(Some(Duration::from_secs(30)));
let _ = builder;Sourcepub fn linger(self, duration: Option<Duration>) -> Self
pub fn linger(self, duration: Option<Duration>) -> Self
Configure TCP linger behaviour for the connection.
§Examples
use std::time::Duration;
use wireframe::client::WireframeClientBuilder;
let builder = WireframeClientBuilder::new().linger(Some(Duration::from_secs(1)));
let _ = builder;Sourcepub fn send_buffer_size(self, size: u32) -> Self
pub fn send_buffer_size(self, size: u32) -> Self
Configure the socket send buffer size.
§Examples
use wireframe::client::WireframeClientBuilder;
let builder = WireframeClientBuilder::new().send_buffer_size(4096);
let _ = builder;Sourcepub fn recv_buffer_size(self, size: u32) -> Self
pub fn recv_buffer_size(self, size: u32) -> Self
Configure the socket receive buffer size.
§Examples
use wireframe::client::WireframeClientBuilder;
let builder = WireframeClientBuilder::new().recv_buffer_size(4096);
let _ = builder;Sourcepub fn reuseaddr(self, enabled: bool) -> Self
pub fn reuseaddr(self, enabled: bool) -> Self
Configure SO_REUSEADDR for the connection.
§Examples
use wireframe::client::WireframeClientBuilder;
let builder = WireframeClientBuilder::new().reuseaddr(true);
let _ = builder;Sourcepub fn reuseport(self, enabled: bool) -> Self
pub fn reuseport(self, enabled: bool) -> Self
Configure SO_REUSEPORT for the connection on supported platforms.
§Examples
use wireframe::client::WireframeClientBuilder;
let builder = WireframeClientBuilder::new().reuseport(true);
let _ = builder;Sourcepub fn with_preamble<Q>(self, preamble: Q) -> WireframeClientBuilder<S, Q>
pub fn with_preamble<Q>(self, preamble: Q) -> WireframeClientBuilder<S, Q>
Configure a preamble to send before exchanging frames.
The preamble is written to the server immediately after establishing
the TCP connection, before the framing layer begins. Use
on_preamble_success to read the server’s
response and preamble_timeout to bound the
exchange.
§Examples
use wireframe::client::WireframeClientBuilder;
#[derive(bincode::Encode)]
struct MyPreamble {
version: u16,
}
let builder = WireframeClientBuilder::new().with_preamble(MyPreamble { version: 1 });
let _ = builder;Source§impl<S, P> WireframeClientBuilder<S, P>
impl<S, P> WireframeClientBuilder<S, P>
Sourcepub async fn connect(
self,
addr: SocketAddr,
) -> Result<WireframeClient<S, RewindStream<TcpStream>>, ClientError>
pub async fn connect( self, addr: SocketAddr, ) -> Result<WireframeClient<S, RewindStream<TcpStream>>, ClientError>
Establish a connection and return a configured client.
If a preamble is configured, it is written to the server before the framing layer is established. The success callback (if registered) is invoked after writing the preamble and may read the server’s response.
§Errors
Returns ClientError if socket configuration, connection, or
preamble exchange fails.
§Examples
use std::net::SocketAddr;
use wireframe::{ClientError, WireframeClient};
let addr: SocketAddr = "127.0.0.1:9000".parse().expect("valid socket address");
let _client = WireframeClient::builder().connect(addr).await?;Source§impl<S, P> WireframeClientBuilder<S, P>
impl<S, P> WireframeClientBuilder<S, P>
Sourcepub fn preamble_timeout(self, duration: Duration) -> Self
pub fn preamble_timeout(self, duration: Duration) -> Self
Configure a timeout for the preamble exchange.
The timeout is applied to the entire preamble phase: writing the preamble and running the success callback (which may read the server’s response). Values below 1 ms are clamped to 1 ms to avoid immediate expiry.
§Examples
use std::time::Duration;
use wireframe::client::WireframeClientBuilder;
#[derive(bincode::Encode)]
struct MyPreamble(u8);
let builder = WireframeClientBuilder::new()
.with_preamble(MyPreamble(1))
.preamble_timeout(Duration::from_secs(1));
let _ = builder;Sourcepub fn on_preamble_success<H>(self, handler: H) -> Self
pub fn on_preamble_success<H>(self, handler: H) -> Self
Register a handler invoked after the preamble is successfully written.
The handler receives the sent preamble and a mutable reference to the TCP stream. It may read the server’s response preamble from the stream. Any leftover bytes (read beyond the server’s response) must be returned so they can be replayed before framed communication begins.
§Examples
use futures::FutureExt;
use wireframe::client::WireframeClientBuilder;
#[derive(bincode::Encode)]
struct MyPreamble(u8);
let builder = WireframeClientBuilder::new()
.with_preamble(MyPreamble(1))
.on_preamble_success(|_preamble, _stream| {
async move {
// Read server response if needed...
Ok(Vec::new()) // No leftover bytes
}
.boxed()
});
let _ = builder;Sourcepub fn on_preamble_failure<H>(self, handler: H) -> Self
pub fn on_preamble_failure<H>(self, handler: H) -> Self
Register a handler invoked when the preamble exchange fails.
The handler receives the error and a mutable reference to the TCP stream, allowing it to log or send an error response before the connection closes.
§Examples
use futures::FutureExt;
use wireframe::client::WireframeClientBuilder;
#[derive(bincode::Encode)]
struct MyPreamble(u8);
let builder = WireframeClientBuilder::new()
.with_preamble(MyPreamble(1))
.on_preamble_failure(|err, _stream| {
async move {
eprintln!("Preamble failed: {err}");
Ok(())
}
.boxed()
});
let _ = builder;