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 std::path::PathBuf;

use crate::types::ResultVoid;

#[derive(Default, PartialEq, Clone, Debug)]
pub enum FileShareStatus {
    #[default]
    Private,
    Server,
    Client,
}

pub trait MFile<D, H, C>: BasicFile<D, H> + HistorianFile<D, H, C> {}

pub trait BasicFile<D, H>: Send + Sync {
    fn get_path(&self) -> &PathBuf;

    fn get_path_str(&self) -> String;

    fn is_dirty(&self) -> bool;

    fn set_dirty(&mut self, dirty: bool);

    fn to_string(&self) -> String;

    fn save(&mut self) -> ResultVoid;

    fn get_raw(&mut self) -> &mut D;

    fn handle_modify(&mut self, history: &H) -> ResultVoid;
}

pub trait HistorianFile<D, H, C>: Send + Sync {
    fn get_version(&self) -> usize;

    fn get_share_status(&self) -> FileShareStatus;

    fn merge_history(&mut self, histories: &[H], cursors: &mut C) -> ResultVoid;

    fn change_share_status(&mut self, status: FileShareStatus) -> bool;
}