pub struct TimestampedValue {
pub value: Vec<u8>,
pub timestamp: u64,
}Expand description
A value with an embedded timestamp for LWW ordering.
Used with the Last-Writer-Wins merge strategy to determine which value should win when concurrent modifications occur.
§Serialization Format
Values are serialized as: [value bytes][8-byte big-endian timestamp]
§Example
use prolly::TimestampedValue;
let tv = TimestampedValue::now(b"hello".to_vec());
let bytes = tv.to_bytes();
let restored = TimestampedValue::from_bytes(&bytes).unwrap();
assert_eq!(restored.value, b"hello");Fields§
§value: Vec<u8>The actual value bytes
timestamp: u64Timestamp in microseconds since epoch
Implementations§
Source§impl TimestampedValue
impl TimestampedValue
Sourcepub fn new(value: Vec<u8>, timestamp: u64) -> Self
pub fn new(value: Vec<u8>, timestamp: u64) -> Self
Create a new timestamped value with the given timestamp.
Sourcepub fn to_bytes(&self) -> Vec<u8> ⓘ
pub fn to_bytes(&self) -> Vec<u8> ⓘ
Serialize to bytes (value + 8-byte timestamp suffix).
Format: [value bytes][8-byte big-endian timestamp]
Sourcepub fn from_bytes(bytes: &[u8]) -> Option<Self>
pub fn from_bytes(bytes: &[u8]) -> Option<Self>
Deserialize from bytes.
Returns None if the byte slice is too short (< 8 bytes).
Trait Implementations§
Source§impl Clone for TimestampedValue
impl Clone for TimestampedValue
Source§fn clone(&self) -> TimestampedValue
fn clone(&self) -> TimestampedValue
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for TimestampedValue
impl Debug for TimestampedValue
impl Eq for TimestampedValue
Source§impl PartialEq for TimestampedValue
impl PartialEq for TimestampedValue
impl StructuralPartialEq for TimestampedValue
Auto Trait Implementations§
impl Freeze for TimestampedValue
impl RefUnwindSafe for TimestampedValue
impl Send for TimestampedValue
impl Sync for TimestampedValue
impl Unpin for TimestampedValue
impl UnsafeUnpin for TimestampedValue
impl UnwindSafe for TimestampedValue
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more