collab-common 0.0.7

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

use crate::{File, FileId, PeerId};

/// TODO: docs
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct FileCreated {
    created_by: PeerId,
    file: File,
    parent: FileId,
}

impl FileCreated {
    /// Returns the [`PeerId`] of the peer that created the file.
    #[inline(always)]
    pub fn created_by(&self) -> PeerId {
        self.created_by
    }

    /// Returns the [`File`] that was created.
    #[inline(always)]
    pub fn file(&self) -> &File {
        &self.file
    }

    /// Returns the [`FileId`] of the parent file.
    ///
    /// The returned `FileId` is guaranteed to be of a
    /// [`Directory`](crate::FileKind::Directory) file, and it's used to figure
    /// out where in the worktree the file should be placed.
    #[inline(always)]
    pub fn parent(&self) -> FileId {
        // We use this instead of the file's path with respect to the root
        // because the latter could change after the file is created but before
        // this event is received by a peer.
        //
        // It's also a lot cheaper to send this over the wire since it's just
        // an integer.
        self.parent
    }
}