pub struct AtomicTimestamp(/* private fields */);Expand description
Atomic wrapper for timestamps used in structs so we can avoid locks for LRU and similar operations
Implementations§
Source§impl AtomicTimestamp
impl AtomicTimestamp
pub fn now() -> Self
pub fn now_non_decreasing() -> Self
pub fn now_increasing() -> Self
pub fn new(t: Timestamp) -> Self
pub fn get(&self) -> Timestamp
pub fn set(&self, t: Timestamp)
Sourcepub fn fetch_update(
&self,
f: impl FnMut(Timestamp) -> Option<Timestamp>,
) -> Result<Timestamp, Timestamp>
pub fn fetch_update( &self, f: impl FnMut(Timestamp) -> Option<Timestamp>, ) -> Result<Timestamp, Timestamp>
Fetch and update the timestamp atomically
Parameters:
- f: A function that takes the current timestamp and returns an optional new timestamp
Returns:
- The new timestamp if the update was successful, otherwise the current timestamp
Sourcepub fn expiration_state(
&self,
cur_ts: Timestamp,
expiration: TimestampDuration,
) -> ExpirationState
pub fn expiration_state( &self, cur_ts: Timestamp, expiration: TimestampDuration, ) -> ExpirationState
Check if a timestamp has expired atomically
Parameters:
- cur_ts: The current timestamp
- expiration: The expiration duration
Returns:
- true if the timestamp has expired, false if it has not
Sourcepub fn update_if_not_expired(
&self,
cur_ts: Timestamp,
expiration: TimestampDuration,
) -> ExpirationState
pub fn update_if_not_expired( &self, cur_ts: Timestamp, expiration: TimestampDuration, ) -> ExpirationState
Check if a timestamp is expired and update it to the current time if it is not, atomically. Useful for LRU caching.
Parameters:
- cur_ts: The current timestamp
- expiration: The expiration duration
Returns:
- true if the timestamp was updated, false if it was expired
Trait Implementations§
Source§impl Clone for AtomicTimestamp
impl Clone for AtomicTimestamp
Source§impl Debug for AtomicTimestamp
impl Debug for AtomicTimestamp
Source§impl Default for AtomicTimestamp
impl Default for AtomicTimestamp
Source§fn default() -> AtomicTimestamp
fn default() -> AtomicTimestamp
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for AtomicTimestamp
impl<'de> Deserialize<'de> for AtomicTimestamp
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
Source§impl Display for AtomicTimestamp
impl Display for AtomicTimestamp
Source§impl From<&AtomicTimestamp> for Timestamp
impl From<&AtomicTimestamp> for Timestamp
Source§fn from(at: &AtomicTimestamp) -> Self
fn from(at: &AtomicTimestamp) -> Self
Converts to this type from the input type.
Source§impl From<AtomicTimestamp> for Timestamp
impl From<AtomicTimestamp> for Timestamp
Source§fn from(at: AtomicTimestamp) -> Self
fn from(at: AtomicTimestamp) -> Self
Converts to this type from the input type.
Source§impl From<Timestamp> for AtomicTimestamp
impl From<Timestamp> for AtomicTimestamp
Source§impl GetSize for AtomicTimestamp
impl GetSize for AtomicTimestamp
Source§fn get_heap_size(&self) -> usize
fn get_heap_size(&self) -> usize
Determines how many bytes this object occupies inside the heap. Read more
Source§fn get_heap_size_with_tracker<TRACKER: GetSizeTracker>(
&self,
tracker: TRACKER,
) -> (usize, TRACKER)
fn get_heap_size_with_tracker<TRACKER: GetSizeTracker>( &self, tracker: TRACKER, ) -> (usize, TRACKER)
Determines how many bytes this object occupies inside the heap while using a
tracker. Read moreSource§fn get_stack_size() -> usize
fn get_stack_size() -> usize
Determines how may bytes this object occupies inside the stack. Read more
Source§fn get_size_with_tracker<T>(&self, tracker: T) -> (usize, T)where
T: GetSizeTracker,
fn get_size_with_tracker<T>(&self, tracker: T) -> (usize, T)where
T: GetSizeTracker,
Determines the total size of the object while using a
tracker. Read moreAuto Trait Implementations§
impl !Freeze for AtomicTimestamp
impl RefUnwindSafe for AtomicTimestamp
impl Send for AtomicTimestamp
impl Sync for AtomicTimestamp
impl Unpin for AtomicTimestamp
impl UnsafeUnpin for AtomicTimestamp
impl UnwindSafe for AtomicTimestamp
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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