ClientBuilder

Struct ClientBuilder 

Source
pub struct ClientBuilder<Protocol = Unspecified, Mode = Unspecified> { /* private fields */ }
Expand description

Type-state builder for OpenIGTLink clients

Uses compile-time type checking to ensure only valid client configurations can be constructed.

§Type Parameters

  • Protocol - Protocol state (Unspecified, TcpConfigured, UdpConfigured)
  • Mode - Mode state (Unspecified, SyncMode, AsyncMode)

§Examples

use openigtlink_rust::io::builder::ClientBuilder;

let client = ClientBuilder::new()
    .tcp("127.0.0.1:18944")
    .sync()
    .build()?;

Implementations§

Source§

impl ClientBuilder<Unspecified, Unspecified>

Source

pub fn new() -> Self

Create a new client builder

This is the starting point for building any OpenIGTLink client.

§Examples
use openigtlink_rust::io::builder::ClientBuilder;

let builder = ClientBuilder::new();
Source§

impl ClientBuilder<Unspecified, Unspecified>

Source

pub fn tcp( self, addr: impl Into<String>, ) -> ClientBuilder<TcpConfigured, Unspecified>

Select TCP protocol

§Arguments
  • addr - Server address (e.g., “127.0.0.1:18944”)
§Examples
use openigtlink_rust::io::builder::ClientBuilder;

let builder = ClientBuilder::new()
    .tcp("127.0.0.1:18944");
Source

pub fn udp( self, addr: impl Into<String>, ) -> ClientBuilder<UdpConfigured, SyncMode>

Select UDP protocol

Note: UDP automatically sets mode to SyncMode as UDP only supports synchronous operation.

§Arguments
  • addr - Server address (e.g., “127.0.0.1:18944”)
§Examples
use openigtlink_rust::io::builder::ClientBuilder;

let builder = ClientBuilder::new()
    .udp("127.0.0.1:18944");
Source§

impl ClientBuilder<TcpConfigured, Unspecified>

Source

pub fn sync(self) -> ClientBuilder<TcpConfigured, SyncMode>

Select synchronous (blocking) mode

§Examples
use openigtlink_rust::io::builder::ClientBuilder;

let builder = ClientBuilder::new()
    .tcp("127.0.0.1:18944")
    .sync();
Source

pub fn async_mode(self) -> ClientBuilder<TcpConfigured, AsyncMode>

Select asynchronous (non-blocking) mode

§Examples
use openigtlink_rust::io::builder::ClientBuilder;

let builder = ClientBuilder::new()
    .tcp("127.0.0.1:18944")
    .async_mode();
Source§

impl ClientBuilder<TcpConfigured, SyncMode>

Source

pub fn build(self) -> Result<SyncIgtlClient>

Build a synchronous TCP client

§Errors

Returns error if connection fails

§Examples
use openigtlink_rust::io::builder::ClientBuilder;

let client = ClientBuilder::new()
    .tcp("127.0.0.1:18944")
    .sync()
    .build()?;
Source§

impl ClientBuilder<TcpConfigured, AsyncMode>

Source

pub fn with_tls(self, config: Arc<ClientConfig>) -> Self

Configure TLS encryption

§Arguments
  • config - TLS client configuration
§Examples
use openigtlink_rust::io::builder::ClientBuilder;
use std::sync::Arc;

let tls_config = rustls::ClientConfig::builder()
    .with_root_certificates(rustls::RootCertStore::empty())
    .with_no_client_auth();

let client = ClientBuilder::new()
    .tcp("127.0.0.1:18944")
    .async_mode()
    .with_tls(Arc::new(tls_config))
    .build()
    .await?;
Source

pub fn with_reconnect(self, config: ReconnectConfig) -> Self

Configure automatic reconnection

§Arguments
  • config - Reconnection strategy configuration
§Examples
use openigtlink_rust::io::builder::ClientBuilder;
use openigtlink_rust::io::reconnect::ReconnectConfig;

let client = ClientBuilder::new()
    .tcp("127.0.0.1:18944")
    .async_mode()
    .with_reconnect(ReconnectConfig::default())
    .build()
    .await?;
Source

pub async fn build(self) -> Result<AsyncIgtlClient>

Build an asynchronous TCP client

Creates the appropriate client variant based on configured options:

  • No options: Plain async TCP client
  • TLS only: TLS-encrypted async client
  • Reconnect only: Auto-reconnecting async client
  • TLS + Reconnect: TLS-encrypted auto-reconnecting client
§Errors

Returns error if connection fails

§Examples
use openigtlink_rust::io::builder::ClientBuilder;

// Plain async client
let client = ClientBuilder::new()
    .tcp("127.0.0.1:18944")
    .async_mode()
    .build()
    .await?;
Source§

impl<Protocol, Mode> ClientBuilder<Protocol, Mode>

Source

pub fn verify_crc(self, verify: bool) -> Self

Enable or disable CRC verification for received messages

Default: true (CRC verification enabled)

§Arguments
  • verify - true to enable CRC verification, false to disable
§Examples
use openigtlink_rust::io::builder::ClientBuilder;

let builder = ClientBuilder::new()
    .tcp("127.0.0.1:18944")
    .sync()
    .verify_crc(false);
Source§

impl ClientBuilder<UdpConfigured, SyncMode>

Source

pub fn build(self) -> Result<UdpClient>

Build a UDP client

UDP clients use a connectionless protocol and require specifying the target address for each send operation using send_to().

§Errors

Returns error if binding to local address fails

§Examples
use openigtlink_rust::io::builder::ClientBuilder;
use openigtlink_rust::protocol::types::TransformMessage;
use openigtlink_rust::protocol::message::IgtlMessage;

let client = ClientBuilder::new()
    .udp("0.0.0.0:0")
    .build()?;

let transform = TransformMessage::identity();
let msg = IgtlMessage::new(transform, "Device")?;
client.send_to(&msg, "127.0.0.1:18944")?;

Trait Implementations§

Source§

impl Default for ClientBuilder<Unspecified, Unspecified>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<Protocol, Mode> Freeze for ClientBuilder<Protocol, Mode>
where Protocol: Freeze,

§

impl<Protocol = Unspecified, Mode = Unspecified> !RefUnwindSafe for ClientBuilder<Protocol, Mode>

§

impl<Protocol, Mode> Send for ClientBuilder<Protocol, Mode>
where Protocol: Send, Mode: Send,

§

impl<Protocol, Mode> Sync for ClientBuilder<Protocol, Mode>
where Protocol: Sync, Mode: Sync,

§

impl<Protocol, Mode> Unpin for ClientBuilder<Protocol, Mode>
where Protocol: Unpin, Mode: Unpin,

§

impl<Protocol = Unspecified, Mode = Unspecified> !UnwindSafe for ClientBuilder<Protocol, Mode>

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