use crate::internal::{ConcretePolicy, Policy, ProcessOutcome};
pub struct Permanent;
impl<R> Policy<R> for Permanent {
type Output = R;
fn concrete() -> ConcretePolicy {
ConcretePolicy::Permanent
}
fn should_skip(_: Option<&ProcessOutcome>) -> bool {
false
}
fn output(value: R) -> Self::Output {
value
}
fn fail() -> Self::Output {
panic!("unreachable")
}
}
pub struct Transient;
impl<R> Policy<R> for Transient {
type Output = Option<R>;
fn concrete() -> ConcretePolicy {
ConcretePolicy::Transient
}
fn should_skip(outcome: Option<&ProcessOutcome>) -> bool {
!matches!(outcome, None | Some(ProcessOutcome::Panicked))
}
fn output(value: R) -> Self::Output {
Some(value)
}
fn fail() -> Self::Output {
None
}
}
pub struct Temporary;
impl<R> Policy<R> for Temporary {
type Output = Option<R>;
fn concrete() -> ConcretePolicy {
ConcretePolicy::Temporary
}
fn should_skip(outcome: Option<&ProcessOutcome>) -> bool {
outcome.is_some()
}
fn output(value: R) -> Self::Output {
Some(value)
}
fn fail() -> Self::Output {
None
}
}