Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to the aspect 0.4 API #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion metered-macro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "metered-macro"
version = "0.9.0"
version = "0.10.0"
authors = ["Simon Chemouil <[email protected]>"]
license = "Apache-2.0 OR MIT"
readme = "../README.md"
Expand Down
6 changes: 3 additions & 3 deletions metered/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "metered"
version = "0.9.0"
version = "0.10.0"
authors = ["Simon Chemouil <[email protected]>"]
license = "Apache-2.0 OR MIT"
readme = "../README.md"
Expand All @@ -13,8 +13,8 @@ categories = ["rust-patterns", "development-tools::profiling", "data-structures"
edition = "2018"

[dependencies]
metered-macro = { version = "0.9.0", path = "../metered-macro" }
aspect = "0.3"
metered-macro = { version = "0.10.0", path = "../metered-macro" }
aspect = "0.4"
hdrhistogram = "7.5"
atomic = "0.5"
parking_lot = "0.12"
Expand Down
4 changes: 1 addition & 3 deletions metered/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,7 @@ macro_rules! measure {
($metric:expr, $e:expr) => {{
let metric = $metric;
let guard = $crate::metric::ExitGuard::new(metric);
let mut result = $e;
guard.on_result(&mut result);
result
guard.on_result($e)
}};
}

Expand Down
9 changes: 5 additions & 4 deletions metered/src/metric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ pub trait Metric<R>: Default + OnResultMut<R> + Clear + Serialize {}

// Needed to force `measure!` to work only with the [`Metric`] trait.
#[doc(hidden)]
pub fn on_result<R, A: Metric<R>>(metric: &A, _enter: <A as Enter>::E, _result: &mut R) -> Advice {
metric.on_result(_enter, _result)
pub fn on_result<R, A: Metric<R>>(metric: &A, _enter: <A as Enter>::E, result: R) -> (Advice, R) {
metric.on_result(_enter, result)
}
/// Handles a metric's lifecycle, guarding against early returns and panics.
pub struct ExitGuard<'a, R, M: Metric<R>> {
Expand All @@ -38,11 +38,12 @@ impl<'a, R, M: Metric<R>> ExitGuard<'a, R, M> {
}

/// If no unexpected exit occurred, record the expression's result.
pub fn on_result(mut self, result: &mut R) {
pub fn on_result(mut self, result: R) -> R {
if let Some(enter) = self.enter.take() {
self.metric.on_result(enter, result);
self.metric.on_result(enter, result).1
} else {
// OnResult called twice - we ignore
result
}
}
}
Expand Down