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
sourceimpl Worker<ConsoleAuthStateHandler, TdJson>
impl Worker<ConsoleAuthStateHandler, TdJson>
pub fn builder() -> WorkerBuilder<ConsoleAuthStateHandler, TdJson>
sourceimpl<A, T> Worker<A, T> where
A: AuthStateHandler + Send + Sync + 'static,
T: TdLibClient + Send + Sync + Clone + 'static,
impl<A, T> Worker<A, T> where
A: AuthStateHandler + Send + Sync + 'static,
T: TdLibClient + Send + Sync + Clone + 'static,
sourcepub async fn get_client_state(
&self,
client: &Client<T>
) -> Result<(ClientState, AuthorizationState)>
pub async fn get_client_state(
&self,
client: &Client<T>
) -> Result<(ClientState, AuthorizationState)>
Returns state of the client.
sourcepub async fn reset_auth(&mut self, client: &mut Client<T>) -> Result<()>
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.
sourcepub async fn wait_auth_state_change(
&self,
client: &Client<T>
) -> Result<Result<ClientState, (Error, UpdateAuthorizationState)>>
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(…)
sourcepub async fn wait_client_state(&self, client: &Client<T>) -> Result<ClientState>
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.
sourcepub async fn bind_client(&mut self, client: Client<T>) -> Result<Client<T>>
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
sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Determines that the worker is running.
sourcepub fn start(&mut self) -> JoinHandle<()>
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.
sourcepub fn stop(&self)
pub fn stop(&self)
Stops the client.
You may want to await JoinHandle retrieved with client.start().await
after calling stop
.
pub async fn handle_auth_state(
&self,
auth_state: &AuthorizationState,
client: &Client<T>
) -> Result<()>
Trait Implementations
sourceimpl<A: Clone, S: Clone> Clone for Worker<A, S> where
A: AuthStateHandler + Send + Sync + 'static,
S: TdLibClient + Send + Sync + Clone + 'static,
impl<A: Clone, S: Clone> Clone for Worker<A, S> where
A: AuthStateHandler + Send + Sync + 'static,
S: TdLibClient + Send + Sync + Clone + 'static,
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more