-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathfile.rs
More file actions
36 lines (32 loc) · 675 Bytes
/
file.rs
File metadata and controls
36 lines (32 loc) · 675 Bytes
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
use super::*;
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
#[serde(deny_unknown_fields)]
pub(crate) struct File {
pub(crate) hash: Hash,
pub(crate) size: u64,
}
impl File {
#[cfg(test)]
pub(crate) fn new(bytes: &[u8]) -> Self {
Self {
hash: Hash::bytes(bytes),
size: bytes.len().into_u64(),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn unknown_fields_are_rejected() {
assert!(
serde_json::from_str::<File>(&format!(
r#"{{"hash": "{}", "size": 0, "foo": null}}"#,
test::HASH,
))
.unwrap_err()
.to_string()
.starts_with("unknown field `foo`")
);
}
}