pub struct AuthTracker { /* private fields */ }Expand description
Generic authentication state tracker for WebSocket connections.
Coordinates authentication attempts by providing a channel-based signaling mechanism. Each authentication attempt receives a dedicated oneshot channel that will be resolved when the server responds.
§Superseding Behavior
If a new authentication attempt begins while a previous one is pending, the old attempt is automatically cancelled with an error. This prevents auth response race conditions during rapid reconnections.
§Thread Safety
All operations are thread-safe and can be called concurrently from multiple tasks.
Implementations§
Source§impl AuthTracker
impl AuthTracker
Sourcepub fn begin(&self) -> AuthResultReceiver
pub fn begin(&self) -> AuthResultReceiver
Begins a new authentication attempt.
Returns a receiver that will be notified when authentication completes. If a previous authentication attempt is still pending, it will be cancelled with an error message indicating it was superseded.
Sourcepub fn succeed(&self)
pub fn succeed(&self)
Marks the current authentication attempt as successful.
Notifies the waiting receiver with Ok(()). This should be called
when the server sends a successful authentication response.
If no authentication attempt is pending, this is a no-op.
Sourcepub fn fail(&self, error: impl Into<String>)
pub fn fail(&self, error: impl Into<String>)
Marks the current authentication attempt as failed.
Notifies the waiting receiver with Err(message). This should be called
when the server sends an authentication error response.
If no authentication attempt is pending, this is a no-op.
Sourcepub async fn wait_for_result<E>(
&self,
timeout: Duration,
receiver: AuthResultReceiver,
) -> Result<(), E>
pub async fn wait_for_result<E>( &self, timeout: Duration, receiver: AuthResultReceiver, ) -> Result<(), E>
Waits for the authentication result with a timeout.
Returns Ok(()) if authentication succeeds, or an error if it fails,
times out, or the channel is closed.
§Type Parameters
E: Error type that implementsFrom<String>for error message conversion
§Errors
Returns an error in the following cases:
- Authentication fails (server rejects credentials)
- Authentication times out (no response within timeout duration)
- Authentication channel closes unexpectedly
- Authentication attempt is superseded by a new attempt
Trait Implementations§
Source§impl Clone for AuthTracker
impl Clone for AuthTracker
Source§fn clone(&self) -> AuthTracker
fn clone(&self) -> AuthTracker
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AuthTracker
impl Debug for AuthTracker
Auto Trait Implementations§
impl Freeze for AuthTracker
impl RefUnwindSafe for AuthTracker
impl Send for AuthTracker
impl Sync for AuthTracker
impl Unpin for AuthTracker
impl UnwindSafe for AuthTracker
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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