use std::borrow::Cow;
#[allow(dead_code)] pub struct TransactionCallbacks<FPreview, FCommit, FRollback, FCancel>
where
FPreview: FnMut(&str),
FCommit: FnMut(&str),
FRollback: FnMut(),
FCancel: FnMut(),
{
pub preview: FPreview,
pub commit: FCommit,
pub rollback: FRollback,
pub cancel: FCancel,
}
impl<FPreview, FCommit, FRollback, FCancel>
TransactionCallbacks<FPreview, FCommit, FRollback, FCancel>
where
FPreview: FnMut(&str),
FCommit: FnMut(&str),
FRollback: FnMut(),
FCancel: FnMut(),
{
#[allow(dead_code)] pub fn run_preview(&mut self, id: &str) {
(self.preview)(id);
}
#[allow(dead_code)]
pub fn run_commit(&mut self, id: &str) {
(self.commit)(id);
}
#[allow(dead_code)]
pub fn run_rollback(&mut self) {
(self.rollback)();
}
#[allow(dead_code)]
pub fn run_cancel(&mut self) {
(self.cancel)();
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[allow(dead_code)] pub enum TransactionEvent {
Preview {
id: Cow<'static, str>,
},
Commit {
id: Cow<'static, str>,
},
Rollback,
Cancel,
ItemAction {
option_id: Cow<'static, str>,
action_id: Cow<'static, str>,
},
}
#[derive(Debug, Default, Clone)]
#[allow(dead_code)] pub struct TransactionLog {
pub events: Vec<TransactionEvent>,
}
impl TransactionLog {
#[allow(dead_code)]
pub fn preview(&mut self, id: impl Into<Cow<'static, str>>) {
self.events
.push(TransactionEvent::Preview { id: id.into() });
}
#[allow(dead_code)]
pub fn commit(&mut self, id: impl Into<Cow<'static, str>>) {
self.events.push(TransactionEvent::Commit { id: id.into() });
}
#[allow(dead_code)]
pub fn rollback(&mut self) {
self.events.push(TransactionEvent::Rollback);
}
#[allow(dead_code)]
pub fn cancel(&mut self) {
self.events.push(TransactionEvent::Cancel);
}
#[allow(dead_code)]
pub fn item_action(
&mut self,
option_id: impl Into<Cow<'static, str>>,
action_id: impl Into<Cow<'static, str>>,
) {
self.events.push(TransactionEvent::ItemAction {
option_id: option_id.into(),
action_id: action_id.into(),
});
}
#[must_use]
#[allow(dead_code)]
pub fn last(&self) -> Option<&TransactionEvent> {
self.events.last()
}
}