collab-common 0.0.7

Code shared by collab's client and server
Documentation
use std::ffi::{OsStr, OsString};

use serde::{Deserialize, Serialize};

use crate::{FileId, PeerId};

/// TODO: docs
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct FileMoved {
    id: FileId,
    moved_by: PeerId,
    new_name: Option<OsString>,
    new_parent: Option<FileId>,
}

impl FileMoved {
    /// Returns the [`FileId`] of the file that was moved.
    #[inline(always)]
    pub fn file_id(&self) -> FileId {
        self.id
    }

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

    /// Returns the file's new name if it was renamed, or `None` otherwise.
    #[inline(always)]
    pub fn new_name(&self) -> Option<&OsStr> {
        self.new_name.as_deref()
    }

    /// Returns the [`FileId`] of the new parent if the file was moved under
    /// a different [`Directory`](crate::Directory), or `None` if it stayed
    /// under the same one.
    #[inline(always)]
    pub fn new_parent(&self) -> Option<FileId> {
        self.new_parent
    }
}