TimedOption

Struct TimedOption 

Source
pub struct TimedOption<T, Ttl> { /* private fields */ }
Expand description

Implementations§

Source§

impl<T, B> TimedOption<T, B>
where B: TtlBackend,

Source

pub fn new(value: T, ttl: B::Duration) -> Self

Some value of type T with a ttl.

Source

pub fn empty() -> Self

No value with a expired ttl

Source

pub fn into_option(self) -> Option<T>

Returns an Option<T>. If the value is some but expired a None is returned.

Source

pub fn as_option(&self) -> Option<&T>

Returns an Option<&T>. If the value is some but expired a None is returned.

Source

pub fn into_timed_value(self) -> TimedValue<T>

Returns an TimedValue<T>.

Source

pub fn as_timed_value(&self) -> TimedValue<&T>

Returns an TimedValue<&T>.

Source

pub fn as_ref(&self) -> TimedOption<&T, B>

Converts from &TimedOption<T> to TimedOption<&T>.

Source

pub fn expire(&mut self)

Expires the current ttl.

Source

pub fn clear(&mut self)

Sets value to None.

Source

pub fn take(&mut self) -> Option<T>

Takes the value out of the TimedOption, returning an Option and leaving a None in its place.

Source

pub fn take_timed_value(&mut self) -> TimedValue<T>

Takes the value out of the TimedOption, Returning a TimedValue and leaving a None in its place.

Source

pub fn is_some(&self) -> bool

Returns true if the timed-option is Some value and has not expired.

Source

pub fn is_none(&self) -> bool

Returns true if the timed-option is None value or it has expired.

Source

pub fn ok_or<E>(self, err: E) -> Result<T, E>

Source

pub fn ok_or_else<E>(self, err: impl FnOnce(Option<T>) -> E) -> Result<T, E>

Source

pub fn map<U>(self, f: impl FnOnce(T) -> U) -> TimedOption<U, B>

Trait Implementations§

Source§

impl<T: Clone, Ttl: Clone> Clone for TimedOption<T, Ttl>

Source§

fn clone(&self) -> TimedOption<T, Ttl>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug, Ttl: Debug> Debug for TimedOption<T, Ttl>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de, T, Ttl> Deserialize<'de> for TimedOption<T, Ttl>
where T: Deserialize<'de>, Ttl: Deserialize<'de>,

Source§

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<T, B> From<TimedOption<T, B>> for Option<T>
where B: TtlBackend,

Source§

fn from(value: TimedOption<T, B>) -> Self

Converts to this type from the input type.
Source§

impl<T, B> From<TimedOption<T, B>> for TimedValue<T>
where B: TtlBackend,

Source§

fn from(value: TimedOption<T, B>) -> Self

Converts to this type from the input type.
Source§

impl<T, Ttl> Serialize for TimedOption<T, Ttl>
where T: Serialize, Ttl: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T: Copy, Ttl: Copy> Copy for TimedOption<T, Ttl>

Auto Trait Implementations§

§

impl<T, Ttl> Freeze for TimedOption<T, Ttl>
where Ttl: Freeze, T: Freeze,

§

impl<T, Ttl> RefUnwindSafe for TimedOption<T, Ttl>

§

impl<T, Ttl> Send for TimedOption<T, Ttl>
where Ttl: Send, T: Send,

§

impl<T, Ttl> Sync for TimedOption<T, Ttl>
where Ttl: Sync, T: Sync,

§

impl<T, Ttl> Unpin for TimedOption<T, Ttl>
where Ttl: Unpin, T: Unpin,

§

impl<T, Ttl> UnwindSafe for TimedOption<T, Ttl>
where Ttl: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,