use crate::{domain::SelfKey, error::NoError};
use std::borrow::Borrow;
pub trait Satisfiable<State, Goal> {
type SatisfactionError;
fn is_satisfied(
&self,
by_state: &State,
for_goal: &Goal,
) -> Result<bool, Self::SatisfactionError>;
}
impl<State, Goal> Satisfiable<State, Goal> for ()
where
State: Borrow<Goal>,
Goal: PartialEq,
{
type SatisfactionError = NoError;
fn is_satisfied(
&self,
by_state: &State,
for_goal: &Goal,
) -> Result<bool, Self::SatisfactionError> {
Ok(*by_state.borrow() == *for_goal)
}
}
pub trait ArrivalKeyring<Key, Start, Goal> {
type ArrivalKeyError;
type ArrivalKeys<'a>: IntoIterator<Item = Result<Key, Self::ArrivalKeyError>> + 'a
where
Self: 'a,
Self::ArrivalKeyError: 'a,
Key: 'a,
Start: 'a,
Goal: 'a;
fn get_arrival_keys<'a>(&'a self, start: &Start, goal: &Goal) -> Self::ArrivalKeys<'a>
where
Self: 'a,
Self::ArrivalKeyError: 'a,
Key: 'a,
Start: 'a,
Goal: 'a;
}
impl<Key, Start, Goal> ArrivalKeyring<Key, Start, Goal> for ()
where
Goal: SelfKey,
Goal::Key: Borrow<Key>,
Key: Clone,
{
type ArrivalKeyError = NoError;
type ArrivalKeys<'a>
= [Result<Key, NoError>; 1]
where
Key: 'a,
Start: 'a,
Goal: 'a;
fn get_arrival_keys<'a>(&'a self, _: &Start, goal: &Goal) -> Self::ArrivalKeys<'a>
where
Self: 'a,
Self::ArrivalKeyError: 'a,
Key: 'a,
Start: 'a,
Goal: 'a,
{
[Ok(goal.key().borrow().borrow().clone())]
}
}