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 new_from_start_end(
obj: T,
start: Option<SystemTime>,
end: Option<SystemTime>,
) -> Self
pub fn new_from_start_end( obj: T, start: Option<SystemTime>, end: Option<SystemTime>, ) -> Self
Construct a new TimerangeBound object from a given object, start time, and end time.
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, (Option<SystemTime>, Option<SystemTime>))
pub fn dangerously_into_parts( self, ) -> (T, (Option<SystemTime>, Option<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.
Sourcepub fn as_ref(&self) -> TimerangeBound<&T>
pub fn as_ref(&self) -> TimerangeBound<&T>
Return a TimerangeBound
containing a reference
This can be useful to call methods like .check_valid_at
without consuming the inner T
.
Sourcepub fn as_deref(&self) -> TimerangeBound<&T::Target>where
T: Deref,
pub fn as_deref(&self) -> TimerangeBound<&T::Target>where
T: Deref,
Return a TimerangeBound
containing a reference to T
’s Deref
Sourcepub fn bounds(&self) -> (Option<SystemTime>, Option<SystemTime>)
pub fn bounds(&self) -> (Option<SystemTime>, Option<SystemTime>)
Return the underlying time bounds of this object.
Trait Implementations§
Source§impl<T: Clone> Clone for TimerangeBound<T>
impl<T: Clone> Clone for TimerangeBound<T>
Source§fn clone(&self) -> TimerangeBound<T>
fn clone(&self) -> TimerangeBound<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<T: Debug> Debug for TimerangeBound<T>
impl<T: Debug> Debug for TimerangeBound<T>
Source§impl<T> RangeBounds<SystemTime> for TimerangeBound<T>
impl<T> RangeBounds<SystemTime> for TimerangeBound<T>
Source§impl<T> Timebound<T> for TimerangeBound<T>
impl<T> Timebound<T> for TimerangeBound<T>
Source§type Error = TimeValidityError
type Error = TimeValidityError
Source§fn is_valid_at(&self, t: &SystemTime) -> Result<(), Self::Error>
fn is_valid_at(&self, t: &SystemTime) -> Result<(), Self::Error>
Source§fn dangerously_assume_timely(self) -> T
fn dangerously_assume_timely(self) -> T
Source§fn check_valid_at(self, t: &SystemTime) -> Result<T, Self::Error>
fn check_valid_at(self, t: &SystemTime) -> Result<T, Self::Error>
Source§fn check_valid_now(self) -> Result<T, Self::Error>
fn check_valid_now(self) -> Result<T, Self::Error>
Source§fn check_valid_at_opt(self, t: Option<SystemTime>) -> Result<T, Self::Error>
fn check_valid_at_opt(self, t: Option<SystemTime>) -> Result<T, Self::Error>
Auto Trait Implementations§
impl<T> Freeze for TimerangeBound<T>where
T: Freeze,
impl<T> RefUnwindSafe for TimerangeBound<T>where
T: RefUnwindSafe,
impl<T> Send for TimerangeBound<T>where
T: Send,
impl<T> Sync for TimerangeBound<T>where
T: Sync,
impl<T> Unpin for TimerangeBound<T>where
T: Unpin,
impl<T> UnwindSafe for TimerangeBound<T>where
T: UnwindSafe,
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§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>
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>
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