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§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§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,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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 moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T, R> RangeBoundsExt<T> for Rwhere
R: RangeBounds<T>,
T: Ord,
impl<T, R> RangeBoundsExt<T> for Rwhere
R: RangeBounds<T>,
T: Ord,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.Source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
Source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
impl<T> ErasedDestructor for Twhere
T: 'static,
Layout§
Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.