-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nouzan
committed
Sep 29, 2023
1 parent
04f5c46
commit 01aa2ab
Showing
4 changed files
with
67 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use crate::context::{ContextOperator, Value, ValueRef}; | ||
|
||
use super::Layer; | ||
|
||
/// Layer that used to inspect the context. | ||
pub struct Inspect<F>(pub F); | ||
|
||
impl<T, P, F> Layer<T, P> for Inspect<F> | ||
where | ||
P: ContextOperator<T>, | ||
F: Fn(ValueRef<'_, T>) + Clone, | ||
{ | ||
type Output = InspectOperator<P, F>; | ||
|
||
#[inline] | ||
fn layer(&self, operator: P) -> Self::Output { | ||
InspectOperator { | ||
inner: operator, | ||
inspect: self.0.clone(), | ||
} | ||
} | ||
} | ||
|
||
/// Operator that used to inspect the context. | ||
pub struct InspectOperator<P, F> { | ||
inner: P, | ||
inspect: F, | ||
} | ||
|
||
impl<T, P, F> ContextOperator<T> for InspectOperator<P, F> | ||
where | ||
P: ContextOperator<T>, | ||
F: Fn(ValueRef<'_, T>), | ||
{ | ||
type Output = P::Output; | ||
|
||
#[inline] | ||
fn next(&mut self, input: Value<T>) -> Self::Output { | ||
(self.inspect)(input.as_ref()); | ||
self.inner.next(input) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters