battler_wamp/core/
invocation_policy.rs

1/// How a callee should be selected for invocations.
2#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
3pub enum InvocationPolicy {
4    /// Invocation is sent to a single callee.
5    #[default]
6    Single,
7    /// Invocation is sent to a callee in order of registration.
8    RoundRobin,
9    /// Invocation is sent to a random callee.
10    Random,
11    /// Invocation is sent to the first callee.
12    First,
13    /// Invocation is sent to the last callee.
14    Last,
15}
16
17impl TryFrom<&str> for InvocationPolicy {
18    type Error = anyhow::Error;
19    fn try_from(value: &str) -> Result<Self, Self::Error> {
20        match value {
21            "single" => Ok(Self::Single),
22            "roundrobin" => Ok(Self::RoundRobin),
23            "random" => Ok(Self::Random),
24            "first" => Ok(Self::First),
25            "last" => Ok(Self::Last),
26            _ => Err(Self::Error::msg(format!(
27                "invalid invocation policy: {value}"
28            ))),
29        }
30    }
31}
32
33impl Into<&'static str> for InvocationPolicy {
34    fn into(self) -> &'static str {
35        match self {
36            Self::Single => "single",
37            Self::RoundRobin => "roundrobin",
38            Self::Random => "random",
39            Self::First => "first",
40            Self::Last => "last",
41        }
42    }
43}
44
45impl Into<String> for InvocationPolicy {
46    fn into(self) -> String {
47        Into::<&'static str>::into(self).to_owned()
48    }
49}
50
51impl ToString for InvocationPolicy {
52    fn to_string(&self) -> String {
53        (*self).into()
54    }
55}