#[cfg(feature = "try_trait")]
use std::ops::Try;
pub enum Statepoint<N, T> {
Nonterminal(N),
Terminal(T),
}
#[cfg(feature = "try_trait")]
impl<N, T> Try for Statepoint<N, T> {
type Ok = N;
type Error = T;
fn into_result(self) -> Result<N, T> {
match self {
Statepoint::Nonterminal(n) => Result::Ok(n),
Statepoint::Terminal(t) => Result::Err(t)
}
}
fn from_error(term: T) -> Self {
Statepoint::Terminal(term)
}
fn from_ok(nonterm: N) -> Self {
Statepoint::Nonterminal(nonterm)
}
}
pub enum NodeResult<R, T, N> {
Nonterminal(R, N),
Terminal(T)
}
#[cfg(feature = "try_trait")]
impl<R, T, N> Try for NodeResult<R, T, N> {
type Ok = (R, N);
type Error = T;
fn into_result(self) -> Result<(R, N), T> {
match self {
NodeResult::Nonterminal(r, n) => Result::Ok((r, n)),
NodeResult::Terminal(t) => Result::Err(t)
}
}
fn from_error(term: T) -> Self {
NodeResult::Terminal(term)
}
fn from_ok(nonterm: (R, N)) -> Self {
NodeResult::Nonterminal(nonterm.0, nonterm.1)
}
}
pub trait BehaviorTreeNode {
type Input;
type Nonterminal;
type Terminal;
#[cfg(not(feature = "unsized_locals"))]
fn step(self, input: &Self::Input) ->
NodeResult<Self::Nonterminal, Self::Terminal, Self> where
Self: Sized;
#[cfg(feature = "unsized_locals")]
fn step(self, input: &Self::Input) ->
NodeResult<Self::Nonterminal, Self::Terminal, Self>;
}