1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
}
}