1use serde::{Deserialize, Serialize};
2use std::{error::Error, time::SystemTime};
3
4pub mod level;
5
6pub trait Task<'a>: Serialize + Deserialize<'a> {
7 type SharedState: SharedState<'a>;
8
9 fn new(input: s_text_input_f::BlocksWithAnswer) -> Self;
11 fn get_blocks(&self) -> s_text_input_f::BlocksWithAnswer;
12
13 fn next_repetition(
14 &self,
15 shared_state: &Self::SharedState,
16 desired_retention: f64,
17 ) -> SystemTime;
18 fn complete(
22 &mut self,
23 shared_state: &mut Self::SharedState,
24 desired_retention: f64,
25 interaction: &mut impl FnMut(
26 s_text_input_f::Blocks,
27 ) -> std::io::Result<s_text_input_f::Response>,
28 ) -> std::io::Result<()>;
29}
30
31pub trait SharedState<'a>: Default + Serialize + Deserialize<'a> {}
32impl SharedState<'_> for () {}
33
34pub trait SharedStateExt<'a, T: Task<'a>>: SharedState<'a> {
35 fn optimize<'b>(
38 &mut self,
39 tasks: impl IntoIterator<Item = &'b T>,
40 ) -> Result<(), Box<dyn Error>>
41 where
42 T: 'b;
43}