Skip to main content

Session

Struct Session 

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

The unique owner of one native TDLib session.

Use client to issue requests without borrowing the update consumer. This type is intentionally not Clone; graceful closure consumes it.

§Lifecycle

Always drive close to completion before process exit. Dropping the owner revokes new client requests but performs no native close, blocking wait, or join. In-flight native operations are not automatically undone.

Implementations§

Source§

impl Session

Source

pub async fn open(params: setTdlibParameters) -> Result<Self>

Creates a native client session and applies the supplied TDLib parameters.

This does not complete authorization. Use recv_auth and generated authentication requests, or construct with bot. parameters supplies editable defaults for the generated parameter struct.

§Errors

Returns the parameter request’s error. Before returning a failure, attempts graceful closure and preserves the original error if cleanup also fails.

§Cancellation

Drive construction to completion. Dropping this future after native creation abandons the owner without completing graceful closure.

Source

pub async fn bot(params: setTdlibParameters, token: &str) -> Result<Self>

Creates a session and waits for bot authorization to become ready.

Submits the token when TDLib requests authentication. A session that is already ready is reused without verifying it against token; use a fresh directory or explicitly log out when switching accounts.

§Errors

Returns construction or token-request errors, or Error::Auth for an authorization state this narrow helper does not handle. It attempts graceful closure on returned authorization failure, preserving the original error. For custom flows use open and recv_auth.

§Cancellation

Dropping the future abandons construction/authentication and graceful cleanup.

Source

pub fn client(&self) -> Client

Returns a detached request client for this session.

The returned Client holds no borrow of the owner, so it can be used concurrently with recv. Cloning it does not create another native client or extend the owner’s operational lifetime.

Source

pub async fn recv(&mut self) -> Option<Update>

Returns the next non-authorization update, or None after closure.

Updates buffered by recv_auth are returned first, in their original order. Authorization transitions are consumed internally and never returned here; consume them through recv_auth when needed.

Requests and message tracking progress without polling this method, but the unbounded application queue continues to grow until it is drained.

§Cancellation safety

Cancelling a pending receive does not lose an application update. It may already have consumed authorization transitions, which are excluded from this API. Do not alternate this method with recv_auth expecting an auth transition consumed here to be replayed there.

Source

pub async fn recv_auth(&mut self) -> AuthorizationState

Returns the next authorization transition, buffering other updates.

This is an event stream, not a query for the current authorization state. Once closure has been observed, subsequent calls return authorizationStateClosed immediately. Otherwise this can wait indefinitely, including when the client is already ready and no new transition occurs.

Buffered application updates remain available through recv. Cancelling a pending call preserves those buffered updates.

Source

pub async fn close(self) -> Result

Consumes the session and attempts graceful native closure.

Closes request admission, sends TDLib’s generated close, and waits for authorizationStateClosed. It then releases routing and waits for the receiver’s safe idle/ownership transition when necessary. If closure was already consumed, it does not submit another close request.

Application updates remaining at closure are discarded with the owner. Drain any updates your application needs before initiating closure.

§Errors

Returns a close-request error while still clearing local waiters and unregistering the client. An error is not proof that native shutdown finished. Requests racing with closure may complete, receive a TDLib error, or become Error::Disconnected; graceful close is not an application-task join.

§Cancellation

This operation has no built-in deadline and is not cancellation-safe. Dropping its future can interrupt close or unregistration. Keep it driven until it returns; ordinary Drop does not finish the protocol.

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