AsyncIgtlClient

Struct AsyncIgtlClient 

Source
pub struct AsyncIgtlClient { /* private fields */ }
๐Ÿ‘ŽDeprecated since 0.2.0: Use ClientBuilder instead: ClientBuilder::new().tcp(addr).async_mode().build().await
Expand description

Asynchronous OpenIGTLink client

Uses non-blocking I/O with Tokio for high-concurrency scenarios.

ยงExamples

use openigtlink_rust::io::AsyncIgtlClient;
use openigtlink_rust::protocol::types::StatusMessage;
use openigtlink_rust::protocol::message::IgtlMessage;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut client = AsyncIgtlClient::connect("127.0.0.1:18944").await?;

    let status = StatusMessage::ok("Hello");
    let msg = IgtlMessage::new(status, "AsyncClient")?;
    client.send(&msg).await?;

    Ok(())
}

Implementationsยง

Sourceยง

impl AsyncIgtlClient

Source

pub async fn connect(addr: &str) -> Result<Self>

Connect to an OpenIGTLink server asynchronously

ยงArguments
  • addr - Server address (e.g., โ€œ127.0.0.1:18944โ€)
ยงErrors
ยงExamples
use openigtlink_rust::io::AsyncIgtlClient;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = AsyncIgtlClient::connect("127.0.0.1:18944").await?;
    Ok(())
}
Source

pub fn set_verify_crc(&mut self, verify: bool)

Enable or disable CRC verification for received messages

ยงArguments
  • verify - true to enable CRC verification (default), false to disable
ยงSafety

Disabling CRC verification should only be done in trusted environments where data corruption is unlikely (e.g., loopback, local network).

Source

pub fn verify_crc(&self) -> bool

Get current CRC verification setting

Source

pub async fn send<T: Message>(&mut self, msg: &IgtlMessage<T>) -> Result<()>

Send a message to the server asynchronously

ยงArguments
  • msg - Message to send
ยงErrors
ยงExamples
use openigtlink_rust::io::AsyncIgtlClient;
use openigtlink_rust::protocol::types::StatusMessage;
use openigtlink_rust::protocol::message::IgtlMessage;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut client = AsyncIgtlClient::connect("127.0.0.1:18944").await?;

    let status = StatusMessage::ok("Ready");
    let msg = IgtlMessage::new(status, "Client")?;
    client.send(&msg).await?;

    Ok(())
}
Source

pub async fn receive<T: Message>(&mut self) -> Result<IgtlMessage<T>>

Receive a message from the server asynchronously

ยงErrors
ยงExamples
use openigtlink_rust::io::AsyncIgtlClient;
use openigtlink_rust::protocol::types::TransformMessage;
use openigtlink_rust::protocol::message::IgtlMessage;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut client = AsyncIgtlClient::connect("127.0.0.1:18944").await?;
    let msg: IgtlMessage<TransformMessage> = client.receive().await?;
    Ok(())
}
Source

pub async fn set_read_timeout( &mut self, timeout: Option<Duration>, ) -> Result<()>

Set read timeout for the underlying TCP stream

Source

pub async fn set_write_timeout( &mut self, timeout: Option<Duration>, ) -> Result<()>

Set write timeout for the underlying TCP stream

Source

pub async fn set_nodelay(&self, nodelay: bool) -> Result<()>

Enable or disable TCP_NODELAY (Nagleโ€™s algorithm)

Source

pub async fn nodelay(&self) -> Result<bool>

Get the current TCP_NODELAY setting

Source

pub fn local_addr(&self) -> Result<SocketAddr>

Get the local address

Source

pub fn peer_addr(&self) -> Result<SocketAddr>

Get the remote peer address

Source

pub fn into_split(self) -> (AsyncIgtlReader, AsyncIgtlWriter)

Split the client into read and write halves

This allows concurrent reading and writing on separate tasks.

ยงExamples
use openigtlink_rust::io::AsyncIgtlClient;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = AsyncIgtlClient::connect("127.0.0.1:18944").await?;
    let (reader, writer) = client.into_split();

    // Use reader and writer in separate tasks
    Ok(())
}

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