From 8974fc5fa72630b692c347c85a7a44c6b7595a60 Mon Sep 17 00:00:00 2001 From: Michal 'vorner' Vaner Date: Fri, 10 May 2019 22:10:15 +0200 Subject: [PATCH] Allow delegating the Observe trait to other type When the result was fixed to ObserveWhen, it was impossible to simply delegate the trait into an wrapped type. This allows the possibility to return ObserveWhen (which can be Self in the case of the default implementation). Fixes #65. --- src/core/attributes.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/core/attributes.rs b/src/core/attributes.rs index f9467ea..68592a4 100755 --- a/src/core/attributes.rs +++ b/src/core/attributes.rs @@ -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( &self, metric: impl Deref, operation: F, - ) -> ObserveWhen + ) -> ObserveWhen where F: Fn(Instant) -> MetricValue + Send + Sync + 'static, Self: Sized; } impl Observe for T { + type Inner = Self; fn observe( &self, metric: impl Deref,