rstd::counting
This commit is contained in:
parent
c2304cc9d9
commit
988764ab07
@ -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;
|
||||
|
32
src/rstd/counting.rs
Normal file
32
src/rstd/counting.rs
Normal file
@ -0,0 +1,32 @@
|
||||
use crate::func::*;
|
||||
|
||||
pub type CountedInstance = instances::effect::EffectInstance<usize>;
|
||||
|
||||
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<A> = instances::effect::WithEffect<A, usize>;
|
||||
|
||||
impl<A> Counted<A> {
|
||||
pub fn after_resolution(self) -> Self {
|
||||
Counted {
|
||||
value: self.value,
|
||||
effect: self.effect + 1,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn count(&self) -> usize {
|
||||
self.effect
|
||||
}
|
||||
}
|
@ -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<usize>;
|
||||
|
||||
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<A> = instances::effect::WithEffect<A, usize>;
|
||||
|
||||
impl<A> Counted<A> {
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user