diff --git a/src/rstd.rs b/src/rstd.rs index d1092d0..4091798 100644 --- a/src/rstd.rs +++ b/src/rstd.rs @@ -11,6 +11,7 @@ use crate::rcore::*; pub mod atomic; pub mod atomic_object; pub mod collections; +pub mod counting; pub mod inject; pub mod inlining; mod local_origin; diff --git a/src/rstd/counting.rs b/src/rstd/counting.rs new file mode 100644 index 0000000..6e83925 --- /dev/null +++ b/src/rstd/counting.rs @@ -0,0 +1,32 @@ +use crate::func::*; + +pub type CountedInstance = instances::effect::EffectInstance; + +impl instances::effect::Effect for usize { + fn e_pure() -> Self { + 0 + } + + fn e_seq(el: Self, er: Self) -> Self { + std::cmp::max(el, er) + } + + fn e_after(self, effect: Self) -> Self { + self + effect + } +} + +pub type Counted = instances::effect::WithEffect; + +impl Counted { + pub fn after_resolution(self) -> Self { + Counted { + value: self.value, + effect: self.effect + 1, + } + } + + pub fn count(&self) -> usize { + self.effect + } +} diff --git a/src/testing/counted.rs b/src/testing/counted.rs index a4b8302..d1f5da8 100644 --- a/src/testing/counted.rs +++ b/src/testing/counted.rs @@ -1,7 +1,6 @@ -use std::cmp::max; - use crate::func::{context::*, *}; use crate::rcore::*; +use crate::rstd::counting::CountedInstance; use super::*; @@ -25,37 +24,6 @@ impl<'a> Context<'a> for TestContextCounted { } } -pub type CountedInstance = instances::effect::EffectInstance; - -impl instances::effect::Effect for usize { - fn e_pure() -> Self { - 0 - } - - fn e_seq(el: Self, er: Self) -> Self { - max(el, er) - } - - fn e_after(self, effect: Self) -> Self { - self + effect - } -} - -pub type Counted = instances::effect::WithEffect; - -impl Counted { - fn add(self, n: usize) -> Self { - Counted { - value: self.value, - effect: self.effect + n, - } - } - - pub fn count(&self) -> usize { - self.effect - } -} - struct CountedInject; impl<'a> Inject<'a, TestContextCounted> for CountedInject { @@ -63,7 +31,7 @@ impl<'a> Inject<'a, TestContextCounted> for CountedInject { &self, fa: Wrapped<'a, TestContextCounted, A>, ) -> Wrapped<'a, TestContextCounted, A> { - fa.add(1) + fa.after_resolution() } }