IPCClient

Struct IPCClient 

Source
pub struct IPCClient { /* private fields */ }
Expand description

A handle to a client connection.

This is the main entrypoint for making RPC calls, publishing events, or subscribing to topics. Internally it communicates with a background task (the “client actor”) that manages the network connection.

Implementations§

Source§

impl IPCClient

Source

pub async fn connect() -> Result<Self>

Connect to the broker and spawn the client actor.

  • If BROKER_ADDR environment variable is set, it connects via TCP.
  • Otherwise it attempts local IPC:
    • On Unix: connects to a Unix socket at rpc::UNIX_PATH.
    • On Windows: connects to a named pipe at rpc::PIPE_PATH.

Returns a IPCClient that can be used to issue requests.

Source

pub async fn remote_call<U, T>( &self, object: &str, method: &str, args: U, ) -> Result<T>
where T: DeserializeOwned, U: Serialize + Any + 'static,

Call a method on a remote object.

  • object: name of the remote object.
  • method: method name.
  • args: JSON arguments.

Returns the deserialized RpcResponse or an error if the call failed or connection was lost.

Source

pub async fn publish( &self, object: &str, topic: &str, args: &Value, ) -> Result<()>

Publish an event to a remote object/topic.

Unlike [remote_call], this is fire-and-forget: no response is awaited.

Source

pub async fn subscribe( &self, object: &str, topic: &str, ) -> UnboundedReceiver<Value>

Subscribe to events from a remote object/topic.

Returns an mpsc::UnboundedReceiver where updates will be delivered as serde_json::Value.

Source

pub async fn subscribe_async<F>(&self, object: &str, topic: &str, callback: F)
where F: Fn(Value) + Send + Sync + 'static,

Subscribe asynchronously with a callback.

Spawns a background task that invokes callback whenever a new event is received on the subscription.

Source

pub async fn wait_for_object(&self, object: &str) -> Result<()>

Wait until a given object exists on the server.

This polls periodically using [has_object] until success.

Trait Implementations§

Source§

impl Clone for IPCClient

Source§

fn clone(&self) -> IPCClient

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. 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<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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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