Struct tor_checkable::timed::TimerangeBound
source · pub struct TimerangeBound<T> { /* private fields */ }Expand description
A TimeBound object that is valid for a specified range of time.
The range is given as an argument, as in t1..t2.
use std::time::{SystemTime, Duration};
use tor_checkable::{Timebound, TimeValidityError, timed::TimerangeBound};
let now = SystemTime::now();
let one_hour = Duration::new(3600, 0);
// This seven is only valid for another hour!
let seven = TimerangeBound::new(7_u32, ..now+one_hour);
assert_eq!(seven.check_valid_at(&now).unwrap(), 7);
// That consumed the previous seven. Try another one.
let seven = TimerangeBound::new(7_u32, ..now+one_hour);
assert_eq!(seven.check_valid_at(&(now+2*one_hour)),
Err(TimeValidityError::Expired(one_hour)));
Implementations§
source§impl<T> TimerangeBound<T>
impl<T> TimerangeBound<T>
sourcepub fn new<U>(obj: T, range: U) -> Selfwhere
U: RangeBounds<SystemTime>,
pub fn new<U>(obj: T, range: U) -> Selfwhere U: RangeBounds<SystemTime>,
Construct a new TimerangeBound object from a given object and range.
Note that we do not distinguish between inclusive and
exclusive bounds: x..y and x..=y are treated the same
here.
sourcepub fn extend_tolerance(self, d: Duration) -> Self
pub fn extend_tolerance(self, d: Duration) -> Self
Adjust this time-range bound to tolerate an expiration time farther in the future.
sourcepub fn extend_pre_tolerance(self, d: Duration) -> Self
pub fn extend_pre_tolerance(self, d: Duration) -> Self
Adjust this time-range bound to tolerate an initial validity time farther in the past.
sourcepub fn dangerously_map<F, U>(self, f: F) -> TimerangeBound<U>where
F: FnOnce(T) -> U,
pub fn dangerously_map<F, U>(self, f: F) -> TimerangeBound<U>where F: FnOnce(T) -> U,
Consume this TimerangeBound, and return a new one with the same
bounds, applying f to its protected value.
The caller must ensure that f does not make any assumptions about the
timeliness of the protected value, or leak any of its contents in
an inappropriate way.
sourcepub fn dangerously_into_parts(
self
) -> (T, (Bound<SystemTime>, Bound<SystemTime>))
pub fn dangerously_into_parts( self ) -> (T, (Bound<SystemTime>, Bound<SystemTime>))
Consume this TimeRangeBound, and return its underlying time bounds and object.
The caller takes responsibility for making sure that the bounds are actually checked.
sourcepub fn dangerously_peek(&self) -> &T
pub fn dangerously_peek(&self) -> &T
Return a reference to the inner object of this TimeRangeBound, without checking the time interval.
The caller takes responsibility for making sure that nothing is actually done with the inner object that would rely on the bounds being correct, until the bounds are (eventually) checked.