nextcloud_versions/
version.rs1use std::fmt;
4
5#[derive(Clone, Debug, PartialEq, Eq)]
12pub struct FileVersion {
13 pub href: String,
15 pub revision_id: String,
17 pub last_modified: Option<String>,
19 pub content_length: Option<u64>,
21 pub etag: Option<String>,
23}
24
25impl FileVersion {
26 pub fn new(
28 href: impl Into<String>,
29 revision_id: impl Into<String>,
30 last_modified: Option<String>,
31 content_length: Option<u64>,
32 etag: Option<String>,
33 ) -> Self {
34 Self {
35 href: href.into(),
36 revision_id: revision_id.into(),
37 last_modified,
38 content_length,
39 etag,
40 }
41 }
42
43 pub fn href(&self) -> &str {
45 &self.href
46 }
47
48 pub fn revision_id(&self) -> &str {
50 &self.revision_id
51 }
52
53 pub fn last_modified(&self) -> Option<&str> {
55 self.last_modified.as_deref()
56 }
57
58 pub fn content_length(&self) -> Option<u64> {
60 self.content_length
61 }
62
63 pub fn etag(&self) -> Option<&str> {
65 self.etag.as_deref()
66 }
67}
68
69impl fmt::Display for FileVersion {
70 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
71 write!(
72 f,
73 "FileVersion(revision_id={}, href={})",
74 self.revision_id, self.href
75 )
76 }
77}
78
79#[cfg(test)]
80mod tests {
81 use super::FileVersion;
82
83 #[test]
84 fn file_version_accessors_and_display() {
85 let version = FileVersion::new(
86 "/remote.php/dav/versions/alice/versions/123/1609459200",
87 "1609459200",
88 Some("Fri, 01 Jan 2021 00:00:00 GMT".to_string()),
89 Some(1024),
90 Some("\"abcdef\"".to_string()),
91 );
92
93 assert_eq!(
94 version.href(),
95 "/remote.php/dav/versions/alice/versions/123/1609459200"
96 );
97 assert_eq!(version.revision_id(), "1609459200");
98 assert_eq!(
99 version.last_modified(),
100 Some("Fri, 01 Jan 2021 00:00:00 GMT")
101 );
102 assert_eq!(version.content_length(), Some(1024));
103 assert_eq!(version.etag(), Some("\"abcdef\""));
104 assert_eq!(
105 version.to_string(),
106 "FileVersion(revision_id=1609459200, href=/remote.php/dav/versions/alice/versions/123/1609459200)"
107 );
108 }
109}