collab-common 0.0.7

Code shared by collab's client and server
Documentation
use serde::{Deserialize, Serialize};

use crate::{Session, SessionId};

/// The response sent by the server after the client sends an
/// [`InitRequest`](crate::InitRequest).
///
/// This is the first message sent by the
/// server to the client after a connection is established.
#[derive(Debug, Serialize, Deserialize)]
pub enum InitResponse {
    /// The server started a new session with the given [`SessionId`]. This is
    /// sent when the client requested to start a new session by sending a
    /// [`InitRequest::Start`](crate::InitRequest::Start) message.
    Started(SessionId),

    /// The server joined the client to the session specified by the
    /// [`SessionId`] received in the
    /// [`InitRequest::Join`](crate::InitRequest::Join) message, and sends the
    /// current [`Session`] of the session.
    Joined(Session),
}

impl crate::encode::ShouldCompress for InitResponse {
    #[inline(always)]
    fn should_compress(&self) -> bool {
        matches!(self, Self::Joined(_))
    }
}