put synctoken into common module

This commit is contained in:
Lennart
2024-10-28 17:47:00 +01:00
parent db01df5cb8
commit d9b9b0825c
6 changed files with 18 additions and 31 deletions

View File

@@ -1,3 +1,4 @@
use crate::synctoken::format_synctoken;
use chrono::NaiveDateTime;
#[derive(Debug, Clone)]
@@ -15,18 +16,3 @@ impl Addressbook {
format_synctoken(self.synctoken)
}
}
// TODO: make nicer
const SYNC_NAMESPACE: &str = "github.com/lennart-k/rustical/ns/";
pub fn format_synctoken(synctoken: i64) -> String {
format!("{}{}", SYNC_NAMESPACE, synctoken)
}
pub fn parse_synctoken(synctoken: &str) -> Option<i64> {
if !synctoken.starts_with(SYNC_NAMESPACE) {
return None;
}
let (_, synctoken) = synctoken.split_at(SYNC_NAMESPACE.len());
synctoken.parse::<i64>().ok()
}