Allow delegating the Observe trait to other type

When the result was fixed to ObserveWhen<Self, _>, it was impossible to
simply delegate the trait into an wrapped type. This allows the
possibility to return ObserveWhen<Whatever, _> (which can be Self in the
case of the default implementation).

Fixes #65.
This commit is contained in:
Michal 'vorner' Vaner 2019-05-10 22:10:15 +02:00
parent ac19241a58
commit 8974fc5fa7
No known key found for this signature in database
GPG Key ID: F700D0C019E4C66F
1 changed files with 7 additions and 1 deletions

View File

@ -146,18 +146,24 @@ where
/// Schedule a recurring task
pub trait Observe {
/// The inner type for the [`ObserveWhen`].
///
/// The observe can be delegated to a different type then `Self`, however the latter is more
/// common.
type Inner;
/// Provide a source for a metric's values.
fn observe<F>(
&self,
metric: impl Deref<Target = InputMetric>,
operation: F,
) -> ObserveWhen<Self, F>
) -> ObserveWhen<Self::Inner, F>
where
F: Fn(Instant) -> MetricValue + Send + Sync + 'static,
Self: Sized;
}
impl<T: InputScope + WithAttributes> Observe for T {
type Inner = Self;
fn observe<F>(
&self,
metric: impl Deref<Target = InputMetric>,