pub async fn update_connection_state<F>(&self, func: F)
    where
        F: FnOnce(ConnectionState) -> ConnectionState + Sized + Send,
    {
        let mut state = self.inner.state.lock().await;
        let former_state = state.connection_state.clone();
        let update =
            (func)(std::mem::replace(&mut state.connection_state, ConnectionState::Disconnected));
        state.connection_state = update;
        if former_state != state.connection_state {
            let _ = self
                .events
                .push(TargetEvent::ConnectionStateChanged(
                    former_state,
                    state.connection_state.clone(),
                ))
                .await;
        }
    }
/// Allows a client to atomically update the connection state based on what
/// is returned from the predicate.
///
/// For example, if the client wants to update the connection state to RCS
/// connected, but only if the target is already disconnected, it would
/// look like this:
///
/// ```rust
///   let rcs_connection = ...;
///   target.update_connection_state(move |s| {
///     match s {
///       ConnectionState::Disconnected => ConnectionState::Rcs(rcs_connection),
///       _ => s
///     }
///   }).await;
/// ```
///
/// The client must always return the state, as this is swapped with the
/// current target state in-place.
///
/// If the state changes, this will push a `ConnectionStateChanged` event
/// to the event queue.
Allows a client to atomically update the connection state based on what
is returned from the predicate.

For example, if the client wants to update the connection state to RCS
connected, but only if the target is already disconnected, it would
look like this.



The client must always return the state, as this is swapped with the
current target state in-place.

If the state changes, this will push a `ConnectionStateChanged` event
to the event queue.
Allows a client to atomically update the connection state based on what is returned from the predicate . For example if the client wants to update the connection state to RCS connected but only if the target is already disconnected it would look like this . The client must always return the state as this is swapped with the current target state in - place . If the state changes this will push a ` ConnectionStateChanged ` event to the event queue .
pub async fn update_connection_state<F>(&self, func: F)
    where
        F: FnOnce(ConnectionState) -> ConnectionState + Sized + Send,
    {
        let mut state = self.inner.state.lock().await;
        let former_state = state.connection_state.clone();
        let update =
            (func)(std::mem::replace(&mut state.connection_state, ConnectionState::Disconnected));
        state.connection_state = update;
        if former_state != state.connection_state {
            let _ = self
                .events
                .push(TargetEvent::ConnectionStateChanged(
                    former_state,
                    state.connection_state.clone(),
                ))
                .await;
        }
    }
pub async fn update_connection_state < F > ( & self , func : F ) where F : FnOnce ( ConnectionState ) -> ConnectionState + Sized + Send , { let mut state = self . inner . state . lock ( ) . await ; let former_state = state . connection_state . clone ( ) ; let update = ( func ) ( std :: mem :: replace ( & mut state . connection_state , ConnectionState :: Disconnected ) ) ; state . connection_state = update ; if former_state != state . connection_state { let _ = self . events . push ( TargetEvent :: ConnectionStateChanged ( former_state , state . connection_state . clone ( ) , ) ) . await ; } }
Allows a client to atomically update the connection state based on what
is returned from the predicate.
Allows a client to atomically update the connection state based on what is returned from the predicate .
&self
func
F
&self
func
F