collab-common 0.0.7

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

use crate::{PeerId, SessionId};

/// TODO: docs
#[derive(Debug, Clone, Copy, thiserror::Error, Serialize, Deserialize)]
pub enum InitError {
    /// A client tried to join a session before the server removed it but after
    /// the host was already disconnected. This should very rarely happen.
    #[error("the host disconnected from the session")]
    HostDisconnected,

    /// The [`PeerId`] contained in the
    /// [`InitRequest::Join`](crate::InitRequest::Join) message sent by the
    /// client is already present in the session.
    ///
    /// If the [`PeerId`] is generated randomly by the client, this error
    /// should basically never happen.
    #[error("peer {0:?} is already present in the session")]
    PeerAlreadyPresent(PeerId),

    /// The [`SessionId`] contained in the
    /// [`InitRequest::Join`](crate::InitRequest::Join) message sent by the
    /// client does not correspond to an existing session.
    #[error("session {0} does not exist")]
    SessionDoesNotExist(SessionId),
}

impl crate::encode::ShouldCompress for InitError {
    #[inline(always)]
    fn should_compress(&self) -> bool {
        false
    }
}