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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
use crate::data::{DirectoryInformation, File, FileInformation, GeneralHash, OtherInformation, SaveFileEntryTypeV1, SaveFileEntryV1, SaveFileEntryV1Ref, StubInformation, SymlinkInformation};

impl From<FileInformation> for SaveFileEntryV1 {
    fn from(value: FileInformation) -> Self {
        Self {
            file_type: SaveFileEntryTypeV1::File,
            modified: value.modified,
            size: value.content_size,
            hash: value.content_hash,
            path: value.path,
            children: Vec::with_capacity(0),
        }
    }
}

impl From<SymlinkInformation> for SaveFileEntryV1 {
    fn from(value: SymlinkInformation) -> Self {
        Self {
            file_type: SaveFileEntryTypeV1::Symlink,
            modified: value.modified,
            size: value.content_size,
            hash: value.content_hash,
            path: value.path,
            children: Vec::with_capacity(0),
        }
    }
}

impl From<DirectoryInformation> for SaveFileEntryV1 {
    fn from(value: DirectoryInformation) -> Self {
        let mut result = Self {
            file_type: SaveFileEntryTypeV1::Directory,
            modified: value.modified,
            size: value.number_of_children,
            hash: value.content_hash,
            path: value.path,
            children: Vec::with_capacity(value.children.len()),
        };
        for child in value.children {
            result.children.push(child.get_content_hash().clone());
        }
        result
    }
}

impl From<OtherInformation> for SaveFileEntryV1 {
    fn from(value: OtherInformation) -> Self {
        Self {
            file_type: SaveFileEntryTypeV1::Other,
            modified: value.modified,
            size: value.content_size,
            hash: GeneralHash::NULL,
            path: value.path,
            children: Vec::with_capacity(0),
        }
    }
}

impl From<StubInformation> for SaveFileEntryV1 {
    fn from(value: StubInformation) -> Self {
        Self {
            file_type: SaveFileEntryTypeV1::Other,
            modified: 0,
            size: 0,
            hash: value.content_hash,
            path: value.path,
            children: Vec::with_capacity(0),
        }
    }
}

impl<'a> From<&'a FileInformation> for SaveFileEntryV1Ref<'a> {
    fn from(value: &'a FileInformation) -> Self {
        Self {
            file_type: &SaveFileEntryTypeV1::File,
            modified: &value.modified,
            hash: &value.content_hash,
            path: &value.path,
            size: &value.content_size,
            children: Vec::with_capacity(0),
        }
    }
}

impl<'a> From<&'a SymlinkInformation> for SaveFileEntryV1Ref<'a> {
    fn from(value: &'a SymlinkInformation) -> Self {
        Self {
            file_type: &SaveFileEntryTypeV1::Symlink,
            modified: &value.modified,
            hash: &value.content_hash,
            path: &value.path,
            size: &value.content_size,
            children: Vec::with_capacity(0),
        }
    }
}

impl<'a> From<&'a DirectoryInformation> for SaveFileEntryV1Ref<'a> {
    fn from(value: &'a DirectoryInformation) -> Self {
        let mut result = Self {
            file_type: &SaveFileEntryTypeV1::Directory,
            modified: &value.modified,
            hash: &value.content_hash,
            path: &value.path,
            size: &value.number_of_children,
            children: Vec::with_capacity(value.children.len()),
        };
        for child in &value.children {
            result.children.push(child.get_content_hash());
        }
        result
    }
}

impl<'a> From<&'a OtherInformation> for SaveFileEntryV1Ref<'a> {
    fn from(value: &'a OtherInformation) -> Self {
        Self {
            file_type: &SaveFileEntryTypeV1::Other,
            modified: &0,
            hash: &GeneralHash::NULL,
            path: &value.path,
            size: &value.content_size,
            children: Vec::with_capacity(0),
        }
    }
}

impl<'a> From<&'a StubInformation> for SaveFileEntryV1Ref<'a> {
    fn from(value: &'a StubInformation) -> Self {
        Self {
            file_type: &SaveFileEntryTypeV1::Other,
            modified: &0,
            hash: &value.content_hash,
            path: &value.path,
            size: &0,
            children: Vec::with_capacity(0),
        }
    }
}

impl From<File> for SaveFileEntryV1 {
    fn from(value: File) -> Self {
        match value {
            File::File(info) => info.into(),
            File::Directory(info) => info.into(),
            File::Symlink(info) => info.into(),
            File::Other(info) => info.into(),
            File::Stub(info) => info.into(),
        }
    }
}

impl<'a> From<&'a File> for SaveFileEntryV1Ref<'a> {
    fn from(value: &'a File) -> Self {
        match value {
            File::File(info) => info.into(),
            File::Directory(info) => info.into(),
            File::Symlink(info) => info.into(),
            File::Other(info) => info.into(),
            File::Stub(info) => info.into(),
        }
    }
}

impl<'a> From<&'a SaveFileEntryV1> for SaveFileEntryV1Ref<'a> {
    fn from(value: &'a SaveFileEntryV1) -> Self {
        Self {
            file_type: &value.file_type,
            modified: &value.modified,
            hash: &value.hash,
            path: &value.path,
            size: &value.size,
            children: Vec::with_capacity(0),
        }
    }
}