Skip to main content

ephemeris_forge_github/live/
actions.rs

1use std::mem::discriminant;
2
3use crate::operation::actions::{Group, GroupType};
4
5/// The live Actions settings. A group is missing when it was not read or when
6/// GitHub reports its endpoint as unavailable.
7#[derive(Clone, Debug, Default, Eq, PartialEq)]
8pub struct Actions {
9    groups: Vec<Group>,
10}
11
12impl Actions {
13    /// The live group of type `G`.
14    #[must_use]
15    pub fn get<G: GroupType>(&self) -> Option<&G> {
16        self.groups.iter().find_map(G::pick)
17    }
18
19    /// Record a live group, replacing one of the same type.
20    pub fn set<G: Into<Group>>(&mut self, group: G) {
21        let group = group.into();
22        self.groups
23            .retain(|known| discriminant(known) != discriminant(&group));
24        self.groups.push(group);
25    }
26}