pub struct AtomicOptionTimestamp(/* private fields */);Expand description
Atomic wrapper for optional timestamps used in structs so we can avoid locks for LRU and similar operations
Implementations§
Source§impl AtomicOptionTimestamp
impl AtomicOptionTimestamp
pub fn new(opt_ts: Option<Timestamp>) -> Self
pub fn none() -> Self
pub fn now() -> Self
pub fn now_non_decreasing() -> Self
pub fn now_increasing() -> Self
pub fn get(&self) -> Option<Timestamp>
pub fn set(&self, opt_t: Option<Timestamp>)
Sourcepub fn fetch_update(
&self,
f: impl FnMut(Option<Timestamp>) -> Option<Option<Timestamp>>,
) -> Result<Option<Timestamp>, Option<Timestamp>>
pub fn fetch_update( &self, f: impl FnMut(Option<Timestamp>) -> Option<Option<Timestamp>>, ) -> Result<Option<Timestamp>, Option<Timestamp>>
Fetch and update the optional timestamp atomically
Parameters:
- f: A function that takes the current optional timestamp and returns an optional new optional timestamp
Returns:
- The new optional timestamp if the update was successful, otherwise the current optional timestamp
Sourcepub fn expiration_state(
&self,
cur_ts: Timestamp,
expiration: TimestampDuration,
) -> Option<ExpirationState>
pub fn expiration_state( &self, cur_ts: Timestamp, expiration: TimestampDuration, ) -> Option<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 AtomicOptionTimestamp
impl Clone for AtomicOptionTimestamp
Source§impl Debug for AtomicOptionTimestamp
impl Debug for AtomicOptionTimestamp
Source§impl Default for AtomicOptionTimestamp
impl Default for AtomicOptionTimestamp
Source§fn default() -> AtomicOptionTimestamp
fn default() -> AtomicOptionTimestamp
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for AtomicOptionTimestamp
impl<'de> Deserialize<'de> for AtomicOptionTimestamp
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 AtomicOptionTimestamp
impl Display for AtomicOptionTimestamp
Source§impl From<&AtomicOptionTimestamp> for Option<Timestamp>
impl From<&AtomicOptionTimestamp> for Option<Timestamp>
Source§fn from(at: &AtomicOptionTimestamp) -> Self
fn from(at: &AtomicOptionTimestamp) -> Self
Converts to this type from the input type.
Source§impl From<AtomicOptionTimestamp> for Option<Timestamp>
impl From<AtomicOptionTimestamp> for Option<Timestamp>
Source§fn from(at: AtomicOptionTimestamp) -> Self
fn from(at: AtomicOptionTimestamp) -> Self
Converts to this type from the input type.
Source§impl From<Timestamp> for AtomicOptionTimestamp
impl From<Timestamp> for AtomicOptionTimestamp
Source§impl GetSize for AtomicOptionTimestamp
impl GetSize for AtomicOptionTimestamp
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 AtomicOptionTimestamp
impl RefUnwindSafe for AtomicOptionTimestamp
impl Send for AtomicOptionTimestamp
impl Sync for AtomicOptionTimestamp
impl Unpin for AtomicOptionTimestamp
impl UnsafeUnpin for AtomicOptionTimestamp
impl UnwindSafe for AtomicOptionTimestamp
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