Merge pull request #67 from vorner/observe-foreign

Allow delegating the Observe trait to other type
This commit is contained in:
Francis Lalonde 2019-05-10 18:44:20 -04:00 committed by GitHub
commit d2c9d19397
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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>,