use std::fmt;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct FileVersion {
pub href: String,
pub revision_id: String,
pub last_modified: Option<String>,
pub content_length: Option<u64>,
pub etag: Option<String>,
}
impl FileVersion {
pub fn new(
href: impl Into<String>,
revision_id: impl Into<String>,
last_modified: Option<String>,
content_length: Option<u64>,
etag: Option<String>,
) -> Self {
Self {
href: href.into(),
revision_id: revision_id.into(),
last_modified,
content_length,
etag,
}
}
pub fn href(&self) -> &str {
&self.href
}
pub fn revision_id(&self) -> &str {
&self.revision_id
}
pub fn last_modified(&self) -> Option<&str> {
self.last_modified.as_deref()
}
pub fn content_length(&self) -> Option<u64> {
self.content_length
}
pub fn etag(&self) -> Option<&str> {
self.etag.as_deref()
}
}
impl fmt::Display for FileVersion {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"FileVersion(revision_id={}, href={})",
self.revision_id, self.href
)
}
}
#[cfg(test)]
mod tests {
use super::FileVersion;
#[test]
fn file_version_accessors_and_display() {
let version = FileVersion::new(
"/remote.php/dav/versions/alice/versions/123/1609459200",
"1609459200",
Some("Fri, 01 Jan 2021 00:00:00 GMT".to_string()),
Some(1024),
Some("\"abcdef\"".to_string()),
);
assert_eq!(
version.href(),
"/remote.php/dav/versions/alice/versions/123/1609459200"
);
assert_eq!(version.revision_id(), "1609459200");
assert_eq!(
version.last_modified(),
Some("Fri, 01 Jan 2021 00:00:00 GMT")
);
assert_eq!(version.content_length(), Some(1024));
assert_eq!(version.etag(), Some("\"abcdef\""));
assert_eq!(
version.to_string(),
"FileVersion(revision_id=1609459200, href=/remote.php/dav/versions/alice/versions/123/1609459200)"
);
}
}