#[non_exhaustive]
pub struct TimeOptions<F = fn() -> DateTime<Utc>> { pub leeway: Duration, pub clock_fn: F, }
Expand description

Time-related options for token creation and validation.

If the clock crate feature is on (and it’s on by default), TimeOptions can be created using the Default impl or Self::from_leeway(). If the feature is off, you can still create options using a generic constructor.

Examples

// Default options.
let default_options = TimeOptions::default();
let options_with_custom_leeway =
    TimeOptions::from_leeway(Duration::try_seconds(5).unwrap());
// Options that have a fixed time. Can be useful for testing.
let clock_time = Utc::now();
let options_with_stopped_clock =
    TimeOptions::new(Duration::try_seconds(10).unwrap(), move || clock_time);

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§leeway: Duration

Leeway to use during validation.

§clock_fn: F

Source of the current timestamps.

Implementations§

source§

impl<F: Fn() -> DateTime<Utc>> TimeOptions<F>

source

pub fn new(leeway: Duration, clock_fn: F) -> Self

Creates options based on the specified time leeway and clock function.

source§

impl TimeOptions

source

pub fn from_leeway(leeway: Duration) -> Self

Available on crate feature clock only.

Creates options based on the specified time leeway. The clock source is Utc::now().

Trait Implementations§

source§

impl<F: Clone> Clone for TimeOptions<F>

source§

fn clone(&self) -> TimeOptions<F>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<F: Debug> Debug for TimeOptions<F>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for TimeOptions

Creates options with a default leeway (60 seconds) and the Utc::now() clock.

This impl is supported on crate feature clock only.

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<F: Copy> Copy for TimeOptions<F>

Auto Trait Implementations§

§

impl<F> RefUnwindSafe for TimeOptions<F>where F: RefUnwindSafe,

§

impl<F> Send for TimeOptions<F>where F: Send,

§

impl<F> Sync for TimeOptions<F>where F: Sync,

§

impl<F> Unpin for TimeOptions<F>where F: Unpin,

§

impl<F> UnwindSafe for TimeOptions<F>where F: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V