pub trait EffectHandler: Send + Sync {
fn handler_identity(&self) -> String {
crate::session::DEFAULT_HANDLER_ID.to_string()
}
fn handle_send(
&self,
role: &str,
partner: &str,
label: &str,
state: &[Value],
) -> EffectResult<Value>;
fn send_decision_fast_path(
&self,
_fast_path: SendDecisionFastPathInput<'_>,
_state: &[Value],
_payload: Option<&Value>,
) -> Option<EffectResult<SendDecision>> {
None
}
fn send_decision(&self, input: SendDecisionInput<'_>) -> EffectResult<SendDecision> {
if let Some(payload) = input.payload {
EffectResult::success(SendDecision::Deliver(payload))
} else {
self.handle_send(input.role, input.partner, input.label, input.state)
.map_success(SendDecision::Deliver)
}
}
fn handle_recv(
&self,
role: &str,
partner: &str,
label: &str,
state: &mut Vec<Value>,
payload: &Value,
) -> EffectResult<()>;
fn handle_choose(
&self,
role: &str,
partner: &str,
labels: &[String],
state: &[Value],
) -> EffectResult<String>;
fn step(&self, role: &str, state: &mut Vec<Value>) -> EffectResult<()>;
fn handle_acquire(
&self,
_sid: SessionId,
_role: &str,
_layer: &str,
_state: &[Value],
) -> EffectResult<Value> {
EffectResult::success(Value::Unit)
}
fn handle_release(
&self,
_sid: SessionId,
_role: &str,
_layer: &str,
_evidence: &Value,
_state: &[Value],
) -> EffectResult<()> {
EffectResult::success(())
}
fn topology_events(&self, _tick: u64) -> EffectResult<Vec<TopologyPerturbation>> {
EffectResult::success(Vec::new())
}
fn output_condition_hint(
&self,
_sid: SessionId,
_role: &str,
_state: &[Value],
) -> Option<OutputConditionHint> {
None
}
}
impl<T: EffectHandler + ?Sized> EffectHandler for &T {
fn handler_identity(&self) -> String {
(**self).handler_identity()
}
fn handle_send(
&self,
role: &str,
partner: &str,
label: &str,
state: &[Value],
) -> EffectResult<Value> {
(**self).handle_send(role, partner, label, state)
}
fn send_decision(&self, input: SendDecisionInput<'_>) -> EffectResult<SendDecision> {
(**self).send_decision(input)
}
fn send_decision_fast_path(
&self,
fast_path: SendDecisionFastPathInput<'_>,
state: &[Value],
payload: Option<&Value>,
) -> Option<EffectResult<SendDecision>> {
(**self).send_decision_fast_path(fast_path, state, payload)
}
fn handle_recv(
&self,
role: &str,
partner: &str,
label: &str,
state: &mut Vec<Value>,
payload: &Value,
) -> EffectResult<()> {
(**self).handle_recv(role, partner, label, state, payload)
}
fn handle_choose(
&self,
role: &str,
partner: &str,
labels: &[String],
state: &[Value],
) -> EffectResult<String> {
(**self).handle_choose(role, partner, labels, state)
}
fn step(&self, role: &str, state: &mut Vec<Value>) -> EffectResult<()> {
(**self).step(role, state)
}
fn handle_acquire(
&self,
sid: SessionId,
role: &str,
layer: &str,
state: &[Value],
) -> EffectResult<Value> {
(**self).handle_acquire(sid, role, layer, state)
}
fn handle_release(
&self,
sid: SessionId,
role: &str,
layer: &str,
evidence: &Value,
state: &[Value],
) -> EffectResult<()> {
(**self).handle_release(sid, role, layer, evidence, state)
}
fn topology_events(&self, tick: u64) -> EffectResult<Vec<TopologyPerturbation>> {
(**self).topology_events(tick)
}
fn output_condition_hint(
&self,
sid: SessionId,
role: &str,
state: &[Value],
) -> Option<OutputConditionHint> {
(**self).output_condition_hint(sid, role, state)
}
}