pub struct Worker<A, S>where
    A: AuthStateHandler + Send + Sync + 'static,
    S: TdLibClient + Send + Sync + Clone + 'static,{ /* private fields */ }
Expand description

The main object in all interactions. You have to start worker and bind each client with worker using auth_client.

Implementations§

source§

impl Worker<ConsoleAuthStateHandler, TdJson>

source§

impl<A, T> Worker<A, T>where A: AuthStateHandler + Send + Sync + 'static, T: TdLibClient + Send + Sync + Clone + 'static,

source

pub async fn get_client_state( &self, client: &Client<T> ) -> Result<(ClientState, AuthorizationState)>

Returns state of the client.

source

pub async fn reset_auth(&mut self, client: &mut Client<T>) -> Result<()>

Drops authorized client. After method call you cannot interact with TDLib by the client.

source

pub async fn wait_auth_state_change( &self, client: &Client<T> ) -> Result<Result<ClientState, (Error, UpdateAuthorizationState)>>

Method waits for client state changes. If an error occured during authorization flow, you receive AuthorizationState on which it happened. You have to setup channel by call Client::builder().with_auth_state_channel(…)

source

pub async fn wait_client_state(&self, client: &Client<T>) -> Result<ClientState>

Method waits for client state changes. It differ from wait_auth_state_change by error type: you won’t receive (AuthorizationState)[crate::types::authorization_state::AuthorizationState] when error occured. Method may be useful if client already authorized on, for example, previous application startup.

source

pub async fn bind_client(&mut self, client: Client<T>) -> Result<Client<T>>

Binds client with worker and runs authorization routines. Method returns error if worker is not running or client already bound

source

pub async fn reload_client(&mut self, client: Client<T>) -> Result<Client<T>>

source

pub fn is_running(&self) -> bool

Determines that the worker is running.

source

pub fn start(&mut self) -> JoinHandle<()>

Starts interaction with TDLib. It returns JoinHandle which allows you to handle worker state: if it yields - so worker is definitely stopped.

source

pub fn stop(&self)

Stops the client. You may want to await JoinHandle retrieved with client.start().await after calling stop.

source

pub async fn handle_auth_state( &self, auth_state: &AuthorizationState, client: &Client<T> ) -> Result<()>

Trait Implementations§

source§

impl<A, S> Clone for Worker<A, S>where A: AuthStateHandler + Send + Sync + 'static + Clone, S: TdLibClient + Send + Sync + Clone + 'static + Clone,

source§

fn clone(&self) -> Worker<A, S>

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl<A, S> Debug for Worker<A, S>where A: AuthStateHandler + Send + Sync + 'static + Debug, S: TdLibClient + Send + Sync + Clone + 'static + Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<A, S> Drop for Worker<A, S>where A: AuthStateHandler + Send + Sync + 'static, S: TdLibClient + Send + Sync + Clone + 'static,

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<A, S> !RefUnwindSafe for Worker<A, S>

§

impl<A, S> Send for Worker<A, S>

§

impl<A, S> Sync for Worker<A, S>

§

impl<A, S> Unpin for Worker<A, S>where S: Unpin,

§

impl<A, S> !UnwindSafe for Worker<A, S>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> DynClone for Twhere T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.