Skip to content
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 aspect/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aspect"
version = "0.3.0"
version = "0.4.0"
authors = ["Simon Chemouil <[email protected]>"]
license = "Apache-2.0 OR MIT"
readme = "../README.md"
Expand Down
15 changes: 9 additions & 6 deletions aspect/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,16 @@ pub trait OnResult<R>: Enter {
}
}

/// The `OnResult` trait is implemented on Aspects to get notified when an expression has returned, and provide
/// the possibility to alter the result.
/// The `OnResultMut` trait is implemented on Aspects to get notified
/// when an expression has returned, and provide the possibility to
/// replace the result.
pub trait OnResultMut<R>: Enter {
/// Called when an expression has returned.
///
/// This function is passed both the enter return value, and the expression return value.
fn on_result(&self, enter: <Self as Enter>::E, _result: &mut R) -> Advice {
self.leave_scope(enter)
fn on_result(&self, enter: <Self as Enter>::E, result: R) -> (Advice, R) {
let advice = self.leave_scope(enter);
(advice, result)
}

/// Called when an expression has exited, but the return value isn't known.
Expand All @@ -73,8 +75,9 @@ pub trait OnResultMut<R>: Enter {
}

impl<R, A: OnResult<R>> OnResultMut<R> for A {
fn on_result(&self, enter: <Self as Enter>::E, result: &mut R) -> Advice {
<Self as OnResult<R>>::on_result(self, enter, result)
fn on_result(&self, enter: <Self as Enter>::E, result: R) -> (Advice, R) {
let advice = <Self as OnResult<R>>::on_result(self, enter, &result);
(advice, result)
}

fn leave_scope(&self, enter: <Self as Enter>::E) -> Advice {
Expand Down