use crate::error::NoError;
pub trait Extrapolator<State, Target, Guidance, Key> {
type Extrapolation;
type ExtrapolationError;
type ExtrapolationIter<'a>: IntoIterator<Item = Result<(Self::Extrapolation, State), Self::ExtrapolationError>>
+ 'a
where
Self: 'a,
Self::Extrapolation: 'a,
Self::ExtrapolationError: 'a,
State: 'a,
Target: 'a,
Guidance: 'a,
Key: 'a;
fn extrapolate<'a>(
&'a self,
from_state: &State,
to_target: &Target,
with_guidance: &Guidance,
for_keys: (Option<&Key>, Option<&Key>),
) -> Self::ExtrapolationIter<'a>
where
Self: 'a,
Self::Extrapolation: 'a,
Self::ExtrapolationError: 'a,
State: 'a,
Target: 'a,
Guidance: 'a,
Key: 'a;
}
pub trait IncrementalExtrapolator<State, Target, Guidance, Key> {
type IncrementalExtrapolation;
type IncrementalExtrapolationError;
type IncrementalExtrapolationIter<'a>: IntoIterator<
Item = Result<
(Self::IncrementalExtrapolation, State, ExtrapolationProgress),
Self::IncrementalExtrapolationError,
>,
> + 'a
where
Self: 'a,
Self::IncrementalExtrapolation: 'a,
Self::IncrementalExtrapolationError: 'a,
State: 'a,
Target: 'a,
Guidance: 'a,
Key: 'a;
fn incremental_extrapolate<'a>(
&'a self,
from_state: &State,
to_target: &Target,
with_guidance: &Guidance,
for_keys: (Option<&Key>, Option<&Key>),
) -> Self::IncrementalExtrapolationIter<'a>
where
Self: 'a,
Self::IncrementalExtrapolation: 'a,
Self::IncrementalExtrapolationError: 'a,
State: 'a,
Target: 'a,
Guidance: 'a,
Key: 'a;
}
#[derive(Debug, Clone, Copy)]
pub enum ExtrapolationProgress {
Incomplete,
Arrived,
}
impl ExtrapolationProgress {
pub fn incomplete(&self) -> bool {
matches!(self, ExtrapolationProgress::Incomplete)
}
pub fn arrived(&self) -> bool {
matches!(self, ExtrapolationProgress::Arrived)
}
}
pub struct NoExtrapolation<E>(std::marker::PhantomData<E>);
impl<State, Target, Guidance, Key, E> Extrapolator<State, Target, Guidance, Key>
for NoExtrapolation<E>
{
type Extrapolation = E;
type ExtrapolationError = NoError;
type ExtrapolationIter<'a>
= [Result<(E, State), NoError>; 0]
where
E: 'a,
State: 'a,
Target: 'a,
Guidance: 'a,
Key: 'a;
fn extrapolate<'a>(
&'a self,
_: &State,
_: &Target,
_: &Guidance,
_: (Option<&Key>, Option<&Key>),
) -> [Result<(E, State), NoError>; 0]
where
E: 'a,
State: 'a,
Target: 'a,
Guidance: 'a,
Key: 'a,
{
[]
}
}
impl<State, Target, Guidance, Key, E> IncrementalExtrapolator<State, Target, Guidance, Key>
for NoExtrapolation<E>
{
type IncrementalExtrapolation = E;
type IncrementalExtrapolationError = NoError;
type IncrementalExtrapolationIter<'a>
= [Result<(E, State, ExtrapolationProgress), NoError>; 0]
where
E: 'a,
State: 'a,
Target: 'a,
Guidance: 'a,
Key: 'a;
fn incremental_extrapolate<'a>(
&'a self,
_: &State,
_: &Target,
_: &Guidance,
_: (Option<&Key>, Option<&Key>),
) -> [Result<(E, State, ExtrapolationProgress), NoError>; 0]
where
E: 'a,
State: 'a,
Target: 'a,
Guidance: 'a,
Key: 'a,
{
[]
}
}