use std::{cell::RefCell, rc::Rc};
use crate::automaton::NextState;
pub trait AutomatonState<'a, Id, D, E> {
fn get_id_owned(&self) -> Id;
fn get_id(&self) -> &Id;
fn execute_next_connection(&self, data: &mut D) -> Result<NextState<'a, Id, D, E>, E>;
}
pub type SharedAutomatonState<'a, Id, D, E> = Rc<RefCell<dyn AutomatonState<'a, Id, D, E> + 'a>>;
pub fn new_shared_automaton_state<'a, Id, D, E, S: AutomatonState<'a, Id, D, E> + 'a>(state: S) -> SharedAutomatonState<'a, Id, D, E> {
Rc::new(RefCell::new(state))
}
pub fn new_shared_concrete_state<'a, Id, D, E, S: AutomatonState<'a, Id, D, E> + 'a>(state: S) -> Rc<RefCell<S>> {
Rc::new(RefCell::new(state))
}
pub fn convert_to_dyn_reference<'a, Id, D, E, S: AutomatonState<'a, Id, D, E> + 'a>(state: Rc<RefCell<S>>) -> SharedAutomatonState<'a, Id, D, E> {
state as SharedAutomatonState<'a, Id, D, E>
}