use serde::{Deserialize, Serialize};
use super::types::SourceLocation;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ConceptKind {
FallibleOperation,
ErrorSignal,
ErrorHandler,
Propagation,
Recovery,
Retry,
Termination,
ResourceCleanup,
StateMutation,
TransactionBoundary,
LoggingOnly,
Placeholder,
UnobservedTask,
PartialCommit,
ContextLoss,
EmptyHandler,
IgnoredFailure,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ConceptInstance {
pub kind: ConceptKind,
pub location: SourceLocation,
pub tag: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub symbol: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub idempotent: Option<bool>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub bounded: Option<bool>,
#[serde(default)]
pub logs_only: bool,
#[serde(default)]
pub drops_context: bool,
#[serde(default)]
pub critical_path: bool,
pub surface: String,
}
impl ConceptInstance {
pub fn new(
kind: ConceptKind,
location: SourceLocation,
tag: impl Into<String>,
surface: impl Into<String>,
) -> Self {
Self {
kind,
location,
tag: tag.into(),
symbol: None,
idempotent: None,
bounded: None,
logs_only: false,
drops_context: false,
critical_path: false,
surface: surface.into(),
}
}
pub fn with_symbol(mut self, s: impl Into<String>) -> Self {
self.symbol = Some(s.into());
self
}
pub fn with_idempotent(mut self, v: bool) -> Self {
self.idempotent = Some(v);
self
}
pub fn with_bounded(mut self, v: bool) -> Self {
self.bounded = Some(v);
self
}
pub fn with_logs_only(mut self, v: bool) -> Self {
self.logs_only = v;
self
}
pub fn with_drops_context(mut self, v: bool) -> Self {
self.drops_context = v;
self
}
pub fn with_critical_path(mut self, v: bool) -> Self {
self.critical_path = v;
self
}
}