Client

Struct Client 

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

The Client interface

This is the primary interface used by clients. It is used to track the state of a connection, and process any incoming or outgoing messages

Implementations§

Source§

impl Client

Source

pub fn new( name: &str, version: Version, ctr_init: u16, sub_paths: &'static [&'static str], pub_short_paths: &'static [&'static str], timeout_ticks: Option<u8>, ) -> Self

Create a new client instance

§Parameters
§name

The name of this device or client

§version

The semantic version number of this client

§ctr_init

A value to initialize the control counter.

You may choose to initialize this with a fixed or random value

§sub_paths

The subscription paths that the device is interested in

This is typically provided by the Table::sub_paths() method on a table type generated using the pubsub_table!() macro.

§pub_paths

The publishing paths that the device is interested in

This is typically provided by the Table::pub_paths() method on a table type generated using the pubsub_table!() macro.

§timeout_ticks

The number of ticks used to time-out waiting for certain responses before retrying automatically.

Set to None to disable automatic retries. This will require the user to manually call Client::reset_connection() if a message is lost.

Ticks are counted by calls to Client::process_one(), which should be called at a semi-regular rate. e.g. if you call process_one() every 10ms, a timeout_ticks: Some(100) would automatically timeout after 1s of waiting for a response.

Source

pub fn reset_connection(&mut self)

Reset the client connection

This immediately disconnects the client, at which point it will begin attemption to re-establish a connection to the broker.

Source

pub fn get_id(&self) -> Option<&Uuid>

Obtain the Uuid assigned by the broker to this client

If the client is not connected, None will be returned.

Source

pub fn is_connected(&self) -> bool

Is the client connected?

Source

pub fn publish<'a, 'b: 'a, C: ClientIo>( &'b self, cio: &mut C, path: &'a str, payload: &'a [u8], ) -> Result<(), Error>

Publish a message

This interface publishes a message from the client to the broker.

§Parameters
§cio

This is the ClientIo instance used by the client

§path

This is the path to publish to. This is typically created by using the Table::serialize() method, which returns a path and the serialized payload

§payload

The serialized payload to publish. This is typically created by using the Table::serialize() method, which returns a path and the serialized payload

Source

pub fn process_one<C: ClientIo, T: Table>( &mut self, cio: &mut C, ) -> Result<Option<RecvMsg<T>>, Error>

Process a single incoming message

This function must be called regularly to process messages that have been received by the broker. It is suggested to call it at regular intervals if you are using the timeout_ticks option when creating the Client.

If a subscription message has been received, it will be returned with the path that was published to. If the Client has subscribed using a wildcard, it may not exactly match the subscription topic

The anachro-icd::matches function can be used to compare if a topic matches a given fixed or wildcard path, if necessary.

Auto Trait Implementations§

§

impl Freeze for Client

§

impl RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl UnwindSafe for Client

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, 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> Same for T

Source§

type Output = T

Should always be Self
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.