Trait is closer to what caldav servers provide

This commit is contained in:
daladim 2021-03-22 22:06:43 +01:00
parent 7af147e417
commit 86f3566532
11 changed files with 122 additions and 94 deletions

View file

@ -7,6 +7,8 @@ use url::Url;
use crate::resource::Resource;
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub enum Item {
Event(crate::event::Event),
@ -35,6 +37,13 @@ impl Item {
}
}
pub fn version_tag(&self) -> &VersionTag {
match self {
Item::Event(e) => e.version_tag(),
Item::Task(t) => t.version_tag(),
}
}
pub fn is_event(&self) -> bool {
match &self {
Item::Event(_) => true,
@ -109,3 +118,24 @@ impl Display for ItemId {
write!(f, "{}", self.content)
}
}
/// A VersionTag is basically a CalDAV `ctag` or `etag`. Whenever it changes, this means the data has changed.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct VersionTag {
tag: String
}
impl From<String> for VersionTag {
fn from(tag: String) -> VersionTag {
Self { tag }
}
}
impl VersionTag {
/// Generate a random VesionTag. This is only useful in tests
pub fn random() -> Self {
let random = uuid::Uuid::new_v4().to_hyphenated().to_string();
Self { tag: random }
}
}