use crate::*;
pub trait Stateful {
type State;
fn state(&self) -> Self::State;
}
pub trait StateAccess {
type State;
unsafe fn get_state_unchecked(&self) -> Self::State;
fn get_final_state(&self) -> Option<Self::State>;
}
impl<T, Tx> StateAccess for TxCatcher<T, Tx>
where
Tx: Stateful,
{
type State = <Tx as Stateful>::State;
unsafe fn get_state_unchecked(&self) -> Self::State {
self.core.state()
}
fn get_final_state(&self) -> Option<Self::State> {
if self.is_finished() {
Some(self.core.state())
} else {
None
}
}
}
impl<T, Tx> Stateful for RawStore<T, Tx>
where
Tx: Stateful,
{
type State = <Tx as Stateful>::State;
fn state(&self) -> Self::State {
self.transform.with(|ptr| (unsafe { &*ptr }).state())
}
}