Struct TtlValue
pub struct TtlValue<T> { /* private fields */ }Expand description
A value that expires after some time.
This value is (de)serializable so it can be persisted in a store.
Implementations§
§impl<T> TtlValue<T>
impl<T> TtlValue<T>
pub const STALE_THRESHOLD: f64
pub const STALE_THRESHOLD: f64
The number of milliseconds after which the data is considered stale.
This matches 1 day.
pub fn without_expiry(data: T) -> TtlValue<T>
pub fn without_expiry(data: T) -> TtlValue<T>
Construct a new TtlValue with the given data that never expires.
pub fn map<U, F>(self, f: F) -> TtlValue<U>where
F: FnOnce(T) -> U,
pub fn map<U, F>(self, f: F) -> TtlValue<U>where
F: FnOnce(T) -> U,
Transform the data of this TtlValue with the given function.
pub fn has_expired(&self) -> bool
pub fn has_expired(&self) -> bool
Whether this value has expired.
pub fn expire(&mut self)
pub fn expire(&mut self)
Mark this value has expired.
pub fn into_data(self) -> T
pub fn into_data(self) -> T
Get the data of this value.
Trait Implementations§
§impl<'de, T> Deserialize<'de> for TtlValue<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for TtlValue<T>where
T: Deserialize<'de>,
§fn deserialize<__D>(
__deserializer: __D,
) -> Result<TtlValue<T>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<TtlValue<T>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
§impl<T> Serialize for TtlValue<T>where
T: Serialize,
impl<T> Serialize for TtlValue<T>where
T: Serialize,
§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
Auto Trait Implementations§
impl<T> Freeze for TtlValue<T>where
T: Freeze,
impl<T> RefUnwindSafe for TtlValue<T>where
T: RefUnwindSafe,
impl<T> Send for TtlValue<T>where
T: Send,
impl<T> Sync for TtlValue<T>where
T: Sync,
impl<T> Unpin for TtlValue<T>where
T: Unpin,
impl<T> UnsafeUnpin for TtlValue<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for TtlValue<T>where
T: UnwindSafe,
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,
§impl<T> CompatExt for T
impl<T> CompatExt for T
Source§impl<T> DropFlavorWrapper<T> for T
impl<T> DropFlavorWrapper<T> for T
Source§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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