inc_complete/computation/
intermediate.rs1use crate::{Cell, DbHandle};
2
3use super::Computation;
4
5#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
10pub struct Intermediate<T>(T);
11
12impl<T> Intermediate<T> {
13 pub const fn new(x: T) -> Self {
14 Self(x)
15 }
16}
17
18pub trait Run {
19 type Output: Eq;
20
21 fn run(&self, handle: &mut DbHandle<impl Computation>) -> Self::Output;
22}
23
24impl<T> Computation for Intermediate<T>
25where
26 T: Run + Clone + 'static,
27{
28 type Output = <T as Run>::Output;
29 type Storage = ();
30
31 fn run(&self, handle: &mut DbHandle<impl Computation>) -> Self::Output {
32 self.0.run(handle)
33 }
34
35 fn input_to_cell(_: &Self, _: &Self::Storage) -> Option<Cell> {
36 panic!(
37 "Intermediate used without a storage type wrapper - try wrapping your type with `HashMapStorage<Intermediate<T>>`"
38 )
39 }
40
41 fn get_function_and_output(_: Cell, _: &Self::Storage) -> (&Self, Option<&Self::Output>) {
42 panic!(
43 "Intermediate used without a storage type wrapper - try wrapping your type with `HashMapStorage<Intermediate<T>>`"
44 )
45 }
46
47 fn set_output(_: Cell, _: Self::Output, _: &mut Self::Storage) {
48 panic!(
49 "Intermediate used without a storage type wrapper - try wrapping your type with `HashMapStorage<Intermediate<T>>`"
50 )
51 }
52
53 fn insert_new_cell(_: Cell, _: Self, _: &mut Self::Storage) {
54 panic!(
55 "Intermediate used without a storage type wrapper - try wrapping your type with `HashMapStorage<Intermediate<T>>`"
56 )
57 }
58}