use std::fmt::{Debug, Display};
use peace_cfg::ApplyCheck;
use peace_resource_rt::type_reg::untagged::{BoxDtDisplay, DataType};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use crate::outcomes::ItemApplyPartialRt;
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct ItemApplyPartial<State, StateDiff> {
pub state_current_stored: Option<State>,
pub state_current: Option<State>,
pub state_target: Option<State>,
pub state_diff: Option<StateDiff>,
pub apply_check: Option<ApplyCheck>,
}
impl<State, StateDiff> ItemApplyPartial<State, StateDiff> {
pub fn new() -> Self {
Self::default()
}
}
impl<State, StateDiff> Default for ItemApplyPartial<State, StateDiff> {
fn default() -> Self {
Self {
state_current_stored: None,
state_current: None,
state_target: None,
state_diff: None,
apply_check: None,
}
}
}
impl<State, StateDiff> ItemApplyPartialRt for ItemApplyPartial<State, StateDiff>
where
State: Clone + Debug + Display + Serialize + DeserializeOwned + Send + Sync + 'static,
StateDiff: Clone + Debug + Display + Serialize + DeserializeOwned + Send + Sync + 'static,
{
fn state_current_stored(&self) -> Option<BoxDtDisplay> {
self.state_current_stored.clone().map(BoxDtDisplay::new)
}
fn state_current(&self) -> Option<BoxDtDisplay> {
self.state_current.clone().map(BoxDtDisplay::new)
}
fn state_target(&self) -> Option<BoxDtDisplay> {
self.state_target.clone().map(BoxDtDisplay::new)
}
fn state_diff(&self) -> Option<BoxDtDisplay> {
self.state_diff.clone().map(BoxDtDisplay::new)
}
fn apply_check(&self) -> Option<ApplyCheck> {
self.apply_check
}
fn as_data_type(&self) -> &dyn DataType {
self
}
fn as_data_type_mut(&mut self) -> &mut dyn DataType {
self
}
}