[][src]Trait envoy_sdk::host::time::Clock

pub trait Clock {
    fn now(&self) -> Result<SystemTime>;
}

An interface of the Envoy Time Service.

Examples

Basic usage of Clock:

use envoy::host::Clock;

let clock = Clock::default();

let system_time = clock.now()?;

Injecting Clock into a HTTP Filter as a dependency:

use envoy::host::Clock;

struct MyHttpFilter<'a> {
    clock: &'a dyn Clock,
}

impl<'a> MyHttpFilter<'a> {
    /// Creates a new instance parameterized with a given [`Clock`] implementation.
    pub fn new(clock: &'a dyn Clock) -> Self {
        MyHttpFilter { clock }
    }

    /// Creates a new instance parameterized with the default [`Clock`] implementation.
    pub fn default() -> Self {
        Self::new(Clock::default())
    }
}

Required methods

fn now(&self) -> Result<SystemTime>

Returns current system time.

Loading content...

Implementations

impl dyn Clock[src]

pub fn default() -> &'static dyn Clock[src]

Returns the default implementation that interacts with Envoy through its ABI.

Implementors

Loading content...