WireframeClientBuilder

Struct WireframeClientBuilder 

Source
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 WireframeClientBuilder<BincodeSerializer, ()>

Source

pub fn new() -> Self

Create a new builder with default settings.

§Examples
use wireframe::client::WireframeClientBuilder;

let builder = WireframeClientBuilder::new();
let _ = builder;
Source§

impl<S, P> WireframeClientBuilder<S, P>
where S: Serializer + Send + Sync,

Source

pub fn serializer<Ser>(self, serializer: Ser) -> WireframeClientBuilder<Ser, P>
where Ser: Serializer + Send + Sync,

Replace the serializer used for encoding and decoding messages.

§Examples
use wireframe::{BincodeSerializer, client::WireframeClientBuilder};

let builder = WireframeClientBuilder::new().serializer(BincodeSerializer);
let _ = builder;
Source

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;
Source

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;
Source

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;
Source

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;
Source

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;
Source

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;
Source

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;
Source

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;
Source

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;
Source

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;
Source

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;
Source

pub fn with_preamble<Q>(self, preamble: Q) -> WireframeClientBuilder<S, Q>
where Q: Encode + Send + Sync + 'static,

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>
where S: Serializer + Send + Sync, P: Encode + Send + Sync + 'static,

Source

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>
where S: Serializer + Send + Sync, P: Encode + Send + Sync + 'static,

Source

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;
Source

pub fn on_preamble_success<H>(self, handler: H) -> Self
where H: for<'a> Fn(&'a P, &'a mut TcpStream) -> BoxFuture<'a, Result<Vec<u8>>> + Send + Sync + 'static,

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;
Source

pub fn on_preamble_failure<H>(self, handler: H) -> Self
where H: for<'a> Fn(&'a ClientError, &'a mut TcpStream) -> BoxFuture<'a, Result<()>> + Send + Sync + 'static,

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;

Trait Implementations§

Source§

impl Default for WireframeClientBuilder<BincodeSerializer, ()>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<S, P> Freeze for WireframeClientBuilder<S, P>
where S: Freeze, P: Freeze,

§

impl<S = BincodeSerializer, P = ()> !RefUnwindSafe for WireframeClientBuilder<S, P>

§

impl<S, P> Send for WireframeClientBuilder<S, P>
where S: Send, P: Send,

§

impl<S, P> Sync for WireframeClientBuilder<S, P>
where S: Sync, P: Sync,

§

impl<S, P> Unpin for WireframeClientBuilder<S, P>
where S: Unpin, P: Unpin,

§

impl<S = BincodeSerializer, P = ()> !UnwindSafe for WireframeClientBuilder<S, P>

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<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> 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, 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<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