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

@@ -8,7 +8,7 @@ use rustical_dav::{
}, },
}; };
use rustical_store::{ use rustical_store::{
calendar::{format_synctoken, parse_synctoken}, synctoken::{format_synctoken, parse_synctoken},
CalendarStore, CalendarStore,
}; };
use serde::Deserialize; use serde::Deserialize;

View File

@@ -12,7 +12,7 @@ use rustical_dav::{
}, },
}; };
use rustical_store::{ use rustical_store::{
addressbook::{format_synctoken, parse_synctoken}, synctoken::{format_synctoken, parse_synctoken},
AddressbookStore, AddressbookStore,
}; };
use serde::Deserialize; use serde::Deserialize;

View File

@@ -1,3 +1,4 @@
use crate::synctoken::format_synctoken;
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@@ -15,18 +16,3 @@ impl Addressbook {
format_synctoken(self.synctoken) 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()
}

View File

@@ -1,3 +1,4 @@
use crate::synctoken::format_synctoken;
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@@ -19,17 +20,3 @@ impl Calendar {
format_synctoken(self.synctoken) format_synctoken(self.synctoken)
} }
} }
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()
}

View File

@@ -6,6 +6,7 @@ pub mod timestamp;
pub use error::Error; pub use error::Error;
pub mod auth; pub mod auth;
pub mod calendar; pub mod calendar;
pub mod synctoken;
pub use addressbook_store::AddressbookStore; pub use addressbook_store::AddressbookStore;
pub use calendar_store::CalendarStore; pub use calendar_store::CalendarStore;

View File

@@ -0,0 +1,13 @@
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()
}