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
impl Session
Sourcepub async fn open(params: setTdlibParameters) -> Result<Self>
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.
Sourcepub async fn bot(params: setTdlibParameters, token: &str) -> Result<Self>
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.
Sourcepub async fn recv(&mut self) -> Option<Update>
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.
Sourcepub async fn recv_auth(&mut self) -> AuthorizationState
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.
Sourcepub async fn close(self) -> Result
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.