pub trait Timebound<T>: Sized {
    type Error;

    // Required methods
    fn is_valid_at(&self, t: &SystemTime) -> Result<(), Self::Error>;
    fn dangerously_assume_timely(self) -> T;

    // Provided methods
    fn check_valid_at(self, t: &SystemTime) -> Result<T, Self::Error> { ... }
    fn check_valid_now(self) -> Result<T, Self::Error> { ... }
    fn check_valid_at_opt(self, t: Option<SystemTime>) -> Result<T, Self::Error> { ... }
}
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.

Required Associated Types§

source

type Error

An error type that’s returned when the object is not timely.

Required Methods§

source

fn is_valid_at(&self, t: &SystemTime) -> Result<(), Self::Error>

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.

source

fn dangerously_assume_timely(self) -> T

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

Provided Methods§

source

fn check_valid_at(self, t: &SystemTime) -> Result<T, Self::Error>

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

source

fn check_valid_now(self) -> Result<T, Self::Error>

Unwrap this Timebound object if it is valid now.

source

fn check_valid_at_opt(self, t: Option<SystemTime>) -> Result<T, Self::Error>

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

Object Safety§

This trait is not object safe.

Implementors§