pub struct SyncState {
pub device_id: String,
pub last_history_index: Option<u16>,
pub total_readings: Option<u16>,
pub last_sync_at: Option<OffsetDateTime>,
}Expand description
Tracks incremental sync progress for a device’s history.
Aranet devices use a ring buffer for history storage, with a 1-based index.
SyncState tracks the last downloaded index so subsequent syncs can
download only new records instead of re-downloading everything.
§Incremental Sync Algorithm
- Read device’s current
total_readingscount - Call
Store::calculate_sync_startto get start index - Download records from
start_indextototal_readings - Call
Store::update_sync_stateto save progress
§Example
use aranet_store::Store;
let store = Store::open_in_memory()?;
store.upsert_device("Aranet4 17C3C", None)?;
// First sync downloads all 500 records
let start = store.calculate_sync_start("Aranet4 17C3C", 500)?;
assert_eq!(start, 1); // Start from beginning
// After syncing, save state
store.update_sync_state("Aranet4 17C3C", 500, 500)?;
// Next sync: device now has 510 records
let start = store.calculate_sync_start("Aranet4 17C3C", 510)?;
assert_eq!(start, 501); // Only download new recordsFields§
§device_id: StringDevice identifier.
last_history_index: Option<u16>Last downloaded history index (1-based).
total_readings: Option<u16>Total readings on device at last sync.
last_sync_at: Option<OffsetDateTime>When the last sync completed.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for SyncState
impl<'de> Deserialize<'de> for SyncState
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for SyncState
impl RefUnwindSafe for SyncState
impl Send for SyncState
impl Sync for SyncState
impl Unpin for SyncState
impl UnsafeUnpin for SyncState
impl UnwindSafe for SyncState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more