Skip to main content

made_core/value_objects/delivery/
follow_replacement.rs

1use std::fmt;
2
3use serde::{Deserialize, Serialize};
4
5/// Whether pending work follows a destination that was replaced.
6///
7/// Named rather than a bare flag because the two answers are different
8/// promises: one says the question stays with the seat, the other says
9/// it stays with the process that was asked and dies with it.
10#[derive(
11    Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize,
12)]
13#[serde(rename_all = "snake_case")]
14pub enum FollowReplacement {
15    /// Leave the delivery superseded and visible; do not re-address it.
16    #[default]
17    Stay,
18    /// Re-address pending deliveries to the replacement.
19    Follow,
20}
21
22impl FollowReplacement {
23    #[must_use]
24    pub const fn follows(self) -> bool {
25        matches!(self, Self::Follow)
26    }
27
28    #[must_use]
29    pub const fn as_str(self) -> &'static str {
30        match self {
31            Self::Stay => "stay",
32            Self::Follow => "follow",
33        }
34    }
35}
36
37impl fmt::Display for FollowReplacement {
38    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
39        formatter.write_str(self.as_str())
40    }
41}