Skip to main content

made_core/ports/
bind_outcome.rs

1use crate::value_objects::IntegratorBinding;
2
3/// What the store did with an offered integrator binding.
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub enum BindOutcome {
6    /// The scope had nobody; this binding holds it now.
7    Bound(IntegratorBinding),
8    /// The same binding was already there; nothing changed.
9    AlreadyBound(IntegratorBinding),
10    /// A different binding was displaced, and the fence went up.
11    Replaced {
12        previous: Box<IntegratorBinding>,
13        current: Box<IntegratorBinding>,
14    },
15    /// A different binding is live and the caller did not ask to replace it.
16    AlreadyExists { existing: Box<IntegratorBinding> },
17}
18
19impl BindOutcome {
20    /// The binding now in force, when the call produced one.
21    #[must_use]
22    pub const fn current(&self) -> Option<&IntegratorBinding> {
23        match self {
24            Self::Bound(binding) | Self::AlreadyBound(binding) => Some(binding),
25            Self::Replaced { current, .. } => Some(current),
26            Self::AlreadyExists { .. } => None,
27        }
28    }
29
30    #[must_use]
31    pub const fn is_bound(&self) -> bool {
32        !matches!(self, Self::AlreadyExists { .. })
33    }
34}