Skip to main content

TimeBound

Trait TimeBound 

Source
pub trait TimeBound: Sized {
    type Inner;

    // Required methods
    fn bounds(&self) -> TimeRange;
    fn dangerously_assume_timely(self) -> Self::Inner;

    // Provided methods
    fn check_valid_at(&self, t: &SystemTime) -> Result<(), TimeValidityError> { ... }
    fn if_valid_at(
        self,
        t: &SystemTime,
    ) -> Result<Self::Inner, TimeValidityError> { ... }
    fn if_valid_now(self) -> Result<Self::Inner, TimeValidityError> { ... }
    fn unwrap_with(self, builder: &mut TimeRangeBoundBuilder) -> Self::Inner { ... }
    fn check_valid_at_opt(
        self,
        t: Option<SystemTime>,
    ) -> Result<Self::Inner, TimeValidityError> { ... }
}
Expand description

A TimeBound object is one that is only valid for a given range of time.

It’s better to wrap things in a TimeBound than to give them an is_valid() valid method, so that you can make sure that nobody uses the object before checking it.

TimeBound implementations are required to be inclusive of the bounds when performing a verification. Mathematically speaking, this means that implementations must check whether x ∊ [start; end] but not x ∊ (start; end).

Required Associated Types§

Source

type Inner

The inner, wrapped type, which is being protected by this TimeBound implementation

Required Methods§

Source

fn bounds(&self) -> TimeRange

Get the bounds, in the form of a TimeRangeBound<()>

It is permissible for the start to be after the end. In that case, it’s simply never valid: either expired, or too soon, or both.

Source

fn dangerously_assume_timely(self) -> Self::Inner

Return the underlying object without checking whether it’s valid.

Provided Methods§

Source

fn check_valid_at(&self, t: &SystemTime) -> Result<(), TimeValidityError>

Check whether this object is valid at a given time.

Return Ok if the object is valid, and an error if the object is not.

Generally, do not implement this method yourself: the provided implementation (which uses bounds) will be correct.

Source

fn if_valid_at(self, t: &SystemTime) -> Result<Self::Inner, TimeValidityError>

Unwrap this TimeBound object if it is valid at a given time.

Source

fn if_valid_now(self) -> Result<Self::Inner, TimeValidityError>

Unwrap this TimeBound object if it is valid now.

Source

fn unwrap_with(self, builder: &mut TimeRangeBoundBuilder) -> Self::Inner

Gain access to the Inner, handling the timeout with a TimeRangeBoundBuilder

Unwraps self, giving access to Self::Inner. Time time bounds are recorded in the TimeRangeBoundBuilder, and will be applied to the T overall return value from the logic closure supplied to TimeRangeBound::build_intersect.

Can only be called within the logic closure to TimeRangeBound::build_intersect.

§CORRECTNESS

Information from the Inner returned from unwrap_with should only be used to help construct the return value from logic. See TimeRangeBound::build_intersect for more details.

Source

fn check_valid_at_opt( self, t: Option<SystemTime>, ) -> Result<Self::Inner, TimeValidityError>

👎Deprecated:

use check_valid_at

Unwrap this object if it is valid at the provided time t. If no time is provided, check the object at the current time.

§Deprecated

We do not believe runtime-selectable current time overrides, via Option<SystemTime>, make sense. We use tor_rtcompat::Runtime for mocking.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§