Skip to main content

Client

Struct Client 

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

The cometd client.

Implementations§

Source§

impl Client

Source

pub fn new( base_url: &str, access_token: &str, timeout: Duration, ) -> Result<Client, Error>

Creates a new cometd client. It is expected to provide the url of the cometd server, the access token to allow the communication and the timeout for long-polling requests.

§Errors

Will return an error if the http client cannot be initalized.

Source

pub fn set_retries(self, retries: i8) -> Self

Sets the number of retries the client will attempt in case of an error or a retry advice is returned by the cometd server.

Source

pub fn connect(&mut self) -> Result<Vec<Response>, Error>

The cometd connect method. It will hang for a response from the server according to the timeout provided to the cometd client. If one or several sucess responses are returned to the request, it will return a Vec containing those responses. If an errored response is received but an advice is provided by the server, the client will try to follow this advice and re-attemp the connection. If the maximum number of retries is reached and the response still does not succeed, it will return an error.

§Errors

The cometd server’s response could not be parsed. The cometd server returned a response that indicated an error and the request could not be retried or the maximum number of retries has been reached.

Source

pub fn disconnect(&mut self) -> Result<Vec<Response>, Error>

The cometd disconnect method. If one or several sucess responses are returned to the request, it will return a Vec containing those responses.

§Errors

The cometd server’s response could not be parsed. The cometd server returned a response that indicated an error and the request could not be retried or the maximum number of retries has been reached.

Source

pub fn init(&mut self) -> Result<Vec<Response>, Error>

Init the cometd client. It will attempt to establish a handshake between the client and the server so it can make further requests.

Source

pub fn subscribe(&mut self, subscription: &str) -> Result<Vec<Response>, Error>

The cometd subscribe method. It will ask the server to subscribe to a certain channel and therefore be updated when something is posted on this channel. If one or several sucess responses are returned to the request, it will return a Vec containing those responses. If an errored response is received but an advice is provided by the server, the client will try to follow this advice and re-attemp the connection. If the maximum number of retries is reached and the response still does not succeed, it will return an error.

§Errors

The cometd server’s response could not be parsed. The cometd server returned a response that indicated an error and the request could not be retried or the maximum number of retries has been reached.

Source

pub fn unsubscribe( &mut self, subscription: &str, ) -> Result<Vec<Response>, Error>

The cometd subscribe method. It will ask the server to unsubscribe from a certain channel and therefore strop being updated when something is posted on this channel. If one or several sucess responses are returned to the request, it will return a Vec containing those responses. If an errored response is received but an advice is provided by the server, the client will try to follow this advice and re-attemp the connection. If the maximum number of retries is reached and the response still does not succeed, it will return an error.

§Errors

The cometd server’s response could not be parsed. The cometd server returned a response that indicated an error and the request could not be retried or the maximum number of retries has been reached.

Source

pub fn publish( &mut self, channel: &str, data: impl Serialize, ) -> Result<Vec<Response>, Error>

The cometd plublish method. It will ask the server to publish a message to a certain channel. If one or several sucess responses are returned to the request, it will return a Vec containing those responses. If an errored response is received but an advice is provided by the server, the client will try to follow this advice and re-attemp the connection. If the maximum number of retries is reached and the response still does not succeed, it will return an error.

§Errors

The cometd server’s response could not be parsed. The cometd server returned a response that indicated an error and the request could not be retried or the maximum number of retries has been reached.

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. 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.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Err = <U as TryFrom<T>>::Err

Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Err>