async fn handle_command(
    frame: Frame,
    subscribe_to: &mut Vec<String>,
    subscriptions: &mut StreamMap<String, Messages>,
    dst: &mut Connection,
) -> crate::Result<()> {
    // A command has been received from the client.
    //
    // Only `SUBSCRIBE` and `UNSUBSCRIBE` commands are permitted
    // in this context.
    match Command::from_frame(frame)? {
        Command::Subscribe(subscribe) => {
            // The `apply` method will subscribe to the channels we add to this
            // vector.
            subscribe_to.extend(subscribe.channels.into_iter());
        }
        Command::Unsubscribe(mut unsubscribe) => {
            // If no channels are specified, this requests unsubscribing from
            // **all** channels. To implement this, the `unsubscribe.channels`
            // vec is populated with the list of channels currently subscribed
            // to.
            if unsubscribe.channels.is_empty() {
                unsubscribe.channels = subscriptions
                    .keys()
                    .map(|channel_name| channel_name.to_string())
                    .collect();
            }

            for channel_name in unsubscribe.channels {
                subscriptions.remove(&channel_name);

                let response = make_unsubscribe_frame(channel_name, subscriptions.len());
                dst.write_frame(&response).await?;
            }
        }
        command => {
            let cmd = Unknown::new(command.get_name());
            cmd.apply(dst).await?;
        }
    }
    Ok(())
}
/// Handle a command received while inside `Subscribe::apply`. Only subscribe
/// and unsubscribe commands are permitted in this context.
///
/// Any new subscriptions are appended to `subscribe_to` instead of modifying
/// `subscriptions`.
Handle a command received while inside `Subscribe::apply`. Only subscribe
and unsubscribe commands are permitted in this context.

Any new subscriptions are appended to `subscribe_to` instead of modifying
`subscriptions`.
Handle a command received while inside ` Subscribe :: apply ` . Only subscribe and unsubscribe commands are permitted in this context . Any new subscriptions are appended to ` subscribe_to ` instead of modifying ` subscriptions ` .
async fn handle_command(
    frame: Frame,
    subscribe_to: &mut Vec<String>,
    subscriptions: &mut StreamMap<String, Messages>,
    dst: &mut Connection,
) -> crate::Result<()> {
    // A command has been received from the client.
    //
    // Only `SUBSCRIBE` and `UNSUBSCRIBE` commands are permitted
    // in this context.
    match Command::from_frame(frame)? {
        Command::Subscribe(subscribe) => {
            // The `apply` method will subscribe to the channels we add to this
            // vector.
            subscribe_to.extend(subscribe.channels.into_iter());
        }
        Command::Unsubscribe(mut unsubscribe) => {
            // If no channels are specified, this requests unsubscribing from
            // **all** channels. To implement this, the `unsubscribe.channels`
            // vec is populated with the list of channels currently subscribed
            // to.
            if unsubscribe.channels.is_empty() {
                unsubscribe.channels = subscriptions
                    .keys()
                    .map(|channel_name| channel_name.to_string())
                    .collect();
            }
            for channel_name in unsubscribe.channels {
                subscriptions.remove(&channel_name);
                let response = make_unsubscribe_frame(channel_name, subscriptions.len());
                dst.write_frame(&response).await?;
            }
        }
        command => {
            let cmd = Unknown::new(command.get_name());
            cmd.apply(dst).await?;
        }
    }
    Ok(())
}
async fn handle_command ( frame : Frame , subscribe_to : & mut Vec < String > , subscriptions : & mut StreamMap < String , Messages > , dst : & mut Connection , ) -> crate :: Result < ( ) > { // A command has been received from the client. // // Only `SUBSCRIBE` and `UNSUBSCRIBE` commands are permitted // in this context. match Command :: from_frame ( frame ) ? { Command :: Subscribe ( subscribe ) => { // The `apply` method will subscribe to the channels we add to this // vector. subscribe_to . extend ( subscribe . channels . into_iter ( ) ) ; } Command :: Unsubscribe ( mut unsubscribe ) => { // If no channels are specified, this requests unsubscribing from // **all** channels. To implement this, the `unsubscribe.channels` // vec is populated with the list of channels currently subscribed // to. if unsubscribe . channels . is_empty ( ) { unsubscribe . channels = subscriptions . keys ( ) . map ( | channel_name | channel_name . to_string ( ) ) . collect ( ) ; } for channel_name in unsubscribe . channels { subscriptions . remove ( & channel_name ) ; let response = make_unsubscribe_frame ( channel_name , subscriptions . len ( ) ) ; dst . write_frame ( & response ) . await ? ; } } command => { let cmd = Unknown :: new ( command . get_name ( ) ) ; cmd . apply ( dst ) . await ? ; } } Ok ( ( ) ) }
Handle a command received while inside `Subscribe::apply`.
Handle a command received while inside ` Subscribe :: apply ` .
frame
Frame
subscribe_to
&mut Vec<String>
subscriptions
&mut StreamMap<String, Messages>
dst
&mut Connection