pub fn update_connection_state<F>(&self, func: F)
    where
        F: FnOnce(ConnectionState) -> ConnectionState + Sized,
    {
        let former_state = self.get_connection_state();
        let mut new_state = (func)(former_state.clone());

        if new_state == ConnectionState::Disconnected {
            if self.is_manual() {
                new_state = ConnectionState::Manual
            }
        }

        if former_state == new_state {
            return;
        }

        self.state.replace(new_state);

        if self.get_connection_state().is_rcs() {
            self.events.push(TargetEvent::RcsActivated).unwrap_or_else(|err| {
                log::warn!("unable to enqueue RCS activation event: {:#}", err)
            });
        }

        self.events
            .push(TargetEvent::ConnectionStateChanged(former_state, self.state.borrow().clone()))
            .unwrap_or_else(|e| log::error!("Failed to push state change for {:?}: {:?}", self, e));
    }
/// 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.
///
/// Some state edges are adjusted or controlled by this method, for
/// example, a state change of a Manually added target to
/// Disconnected will always result in entering the Manual state
/// instead.
///
/// 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.

Some state edges are adjusted or controlled by this method, for
example, a state change of a Manually added target to
Disconnected will always result in entering the Manual state
instead.

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 . Some state edges are adjusted or controlled by this method for example a state change of a Manually added target to Disconnected will always result in entering the Manual state instead . If the state changes this will push a ` ConnectionStateChanged ` event to the event queue .
pub fn update_connection_state<F>(&self, func: F)
    where
        F: FnOnce(ConnectionState) -> ConnectionState + Sized,
    {
        let former_state = self.get_connection_state();
        let mut new_state = (func)(former_state.clone());
        if new_state == ConnectionState::Disconnected {
            if self.is_manual() {
                new_state = ConnectionState::Manual
            }
        }
        if former_state == new_state {
            return;
        }
        self.state.replace(new_state);
        if self.get_connection_state().is_rcs() {
            self.events.push(TargetEvent::RcsActivated).unwrap_or_else(|err| {
                log::warn!("unable to enqueue RCS activation event: {:#}", err)
            });
        }
        self.events
            .push(TargetEvent::ConnectionStateChanged(former_state, self.state.borrow().clone()))
            .unwrap_or_else(|e| log::error!("Failed to push state change for {:?}: {:?}", self, e));
    }
pub fn update_connection_state < F > ( & self , func : F ) where F : FnOnce ( ConnectionState ) -> ConnectionState + Sized , { let former_state = self . get_connection_state ( ) ; let mut new_state = ( func ) ( former_state . clone ( ) ) ; if new_state == ConnectionState :: Disconnected { if self . is_manual ( ) { new_state = ConnectionState :: Manual } } if former_state == new_state { return ; } self . state . replace ( new_state ) ; if self . get_connection_state ( ) . is_rcs ( ) { self . events . push ( TargetEvent :: RcsActivated ) . unwrap_or_else ( | err | { log :: warn ! ( " " err ) } ) ; } self . events . push ( TargetEvent :: ConnectionStateChanged ( former_state , self . state . borrow ( ) . clone ( ) ) ) . unwrap_or_else ( | e | log :: error ! ( " " self e ) ) ; }
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