Skip to main content

sofie_flags/
feature.rs

1use std::marker::PhantomData;
2
3/// `added` and `retire_after_days` are read from the source by `sofie check`, not at run time.
4#[derive(Clone, Copy, Debug, PartialEq, Eq)]
5pub struct Feature {
6    name: &'static str,
7}
8
9impl Feature {
10    /// `name` is `<module>.<flag>`, unique in the app.
11    #[must_use]
12    pub const fn new(name: &'static str) -> Self {
13        Self { name }
14    }
15
16    /// `date` is `YYYY-MM-DD`; `sofie check` reports the flag once it is older than
17    /// `retire_after_days`, 90 unless set.
18    #[must_use]
19    pub const fn added(self, _date: &'static str) -> Self {
20        self
21    }
22
23    #[must_use]
24    pub const fn retire_after_days(self, _days: u32) -> Self {
25        self
26    }
27
28    #[must_use]
29    pub const fn name(self) -> &'static str {
30        self.name
31    }
32}
33
34pub struct Variants<V> {
35    feature: Feature,
36    variant: PhantomData<fn() -> V>,
37}
38
39impl<V> Clone for Variants<V> {
40    fn clone(&self) -> Self {
41        *self
42    }
43}
44
45impl<V> Copy for Variants<V> {}
46
47impl<V> Variants<V> {
48    #[must_use]
49    pub const fn new(name: &'static str) -> Self {
50        Self {
51            feature: Feature::new(name),
52            variant: PhantomData,
53        }
54    }
55
56    #[must_use]
57    pub const fn added(self, _date: &'static str) -> Self {
58        self
59    }
60
61    #[must_use]
62    pub const fn retire_after_days(self, _days: u32) -> Self {
63        self
64    }
65
66    #[must_use]
67    pub const fn feature(self) -> Feature {
68        self.feature
69    }
70}