flexpool-rules 0.4.0

flexpool market rules: dated entries with registered sources, embedded at compile time. No I/O.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
//! flexpool market rules.
//!
//! Every market rule — the day-ahead time unit, a gate closure, a price limit, an order
//! granularity — is a dated entry citing a registered source. Rules are keyed by **delivery day**:
//! the 15-minute day-ahead market went live for delivery day 2025-10-01, so a replay of
//! 2025-09-30 must run hourly and one of 2025-10-01 quarter-hourly.
//!
//! The packs in `rules/` (this crate's, linked from the repository root) are embedded at compile time
//! ([`RuleBook::bundled`]); this crate performs no I/O.

#![forbid(unsafe_code)]

use std::collections::BTreeMap;
use std::fmt;
use std::str::FromStr as _;

use flexpool_core::{EurPerMwh, Granularity, RoundDirection};
use rust_decimal::Decimal;
use serde::{Deserialize, Serialize};
use time::{Date, OffsetDateTime, Time};

const BUNDLED_SOURCES: &str = include_str!("../rules/sources.toml");
const BUNDLED_PACKS: &[(&str, &str)] = &[
    (
        "rules/day-ahead.toml",
        include_str!("../rules/day-ahead.toml"),
    ),
    (
        "rules/intraday.toml",
        include_str!("../rules/intraday.toml"),
    ),
    ("rules/alarms.toml", include_str!("../rules/alarms.toml")),
];

/// How far a source has been confirmed.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum SourceStatus {
    /// The value was confirmed against this primary document.
    Checked,
    /// The best available reference; confirm before a real market depends on it.
    Unverified,
}

/// A registered source.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Source {
    /// Stable id cited by rule entries.
    pub id: String,
    /// Document title.
    pub title: String,
    /// Publisher.
    pub publisher: String,
    /// Retrieval URL.
    pub url: String,
    /// Publication date.
    pub date: Date,
    /// Confirmation status.
    pub status: SourceStatus,
    /// SHA-256 of the mirrored document, once mirrored.
    #[serde(default)]
    pub sha256: Option<String>,
}

/// A rule's value.
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[serde(untagged)]
pub enum Value {
    /// A duration in minutes (market time units).
    Minutes(u16),
    /// A local Berlin time on the delivery day plus an offset in days (gates, publications).
    Gate {
        /// Local wall-clock time in Europe/Berlin.
        local_time: Time,
        /// Days relative to the delivery day (−1 = the day before).
        day_offset: i8,
    },
    /// A price range.
    PriceRange {
        /// Minimum.
        min: EurPerMwh,
        /// Maximum.
        max: EurPerMwh,
    },
    /// A quantity or price step with its rounding direction.
    Step(Granularity),
    /// An alarm type: the rationalised record of ISA-18.2 (priority, delays, texts).
    Alarm(Box<AlarmDef>),
    /// A rate: `count` per `window_secs` (alarm philosophy).
    Rate {
        /// Count.
        count: u32,
        /// Window in seconds.
        window_secs: u32,
    },
    /// A duration in seconds.
    Seconds(u32),
}

/// A text in German and English.
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct Texts {
    /// German.
    pub de: String,
    /// English.
    pub en: String,
}

/// One alarm type, as rationalised: what it means, what to do, how fast, and when it fires.
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct AlarmDef {
    /// 1 high, 2 medium, 3 low.
    pub priority: u8,
    /// Time to respond, minutes.
    pub respond_minutes: u16,
    /// The condition must last this long before the alarm is raised.
    pub on_delay_secs: u32,
    /// The condition must be absent this long before the alarm clears.
    pub off_delay_secs: u32,
    /// A share in (0, 1], for alarms on a ratio (pool availability).
    pub threshold: Option<Decimal>,
    /// Title; `{subject}` is replaced by the connection, asset or pool.
    pub title: Texts,
    /// Likely cause.
    pub cause: Texts,
    /// Consequence if nobody acts.
    pub consequence: Texts,
    /// What the operator does.
    pub action: Texts,
}

/// One dated rule entry.
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct Entry {
    /// Rule id, e.g. `da.mtu`.
    pub id: String,
    /// First delivery day the entry applies to.
    pub valid_from: Date,
    /// First delivery day it no longer applies to (exclusive), if any.
    pub valid_until: Option<Date>,
    /// Source id.
    pub source: String,
    /// What the source says, in a sentence.
    pub clause: String,
    /// The value.
    pub value: Value,
    /// The pack file the entry came from.
    pub pack: String,
}

impl Entry {
    /// Whether the entry applies to `day`.
    #[must_use]
    pub fn applies(&self, day: Date) -> bool {
        self.valid_from <= day && self.valid_until.is_none_or(|until| day < until)
    }
}

/// One problem found while loading rule packs.
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
#[error("{location}: {message}")]
pub struct RuleProblem {
    /// Pack file and rule id, or the registry.
    pub location: String,
    /// What is wrong.
    pub message: String,
}

/// A lookup failed: no entry for this rule and day.
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
#[error("no entry of rule {rule} applies to delivery day {day}")]
pub struct Missing {
    /// Rule id.
    pub rule: String,
    /// Delivery day.
    pub day: Date,
}

/// The loaded rule packs and the source registry.
#[derive(Debug, Clone)]
pub struct RuleBook {
    sources: BTreeMap<String, Source>,
    entries: BTreeMap<String, Vec<Entry>>,
}

#[derive(Deserialize)]
#[serde(deny_unknown_fields)]
struct Registry {
    source: Vec<Source>,
}

#[derive(Deserialize)]
#[serde(deny_unknown_fields)]
struct Pack {
    rule: Vec<RawEntry>,
}

#[derive(Deserialize)]
#[serde(deny_unknown_fields)]
struct RawEntry {
    id: String,
    valid_from: Date,
    valid_until: Option<Date>,
    source: String,
    clause: String,
    minutes: Option<u16>,
    local_time: Option<String>,
    day_offset: Option<i8>,
    min: Option<String>,
    max: Option<String>,
    step: Option<String>,
    direction: Option<String>,
    alarm: Option<RawAlarm>,
    count: Option<u32>,
    window_secs: Option<u32>,
    seconds: Option<u32>,
}

#[derive(Deserialize)]
#[serde(deny_unknown_fields)]
struct RawAlarm {
    priority: u8,
    respond_minutes: u16,
    on_delay_secs: u32,
    off_delay_secs: u32,
    threshold: Option<String>,
    title_de: String,
    title_en: String,
    cause_de: String,
    cause_en: String,
    consequence_de: String,
    consequence_en: String,
    action_de: String,
    action_en: String,
}

fn alarm(raw: &RawAlarm) -> Result<Value, String> {
    if !(1..=3).contains(&raw.priority) {
        return Err(format!("priority {} must be 1, 2 or 3", raw.priority));
    }
    if raw.respond_minutes == 0 {
        return Err("respond_minutes must be positive".to_owned());
    }
    if raw.on_delay_secs > 86_400 || raw.off_delay_secs > 86_400 {
        return Err("delays must be at most one day".to_owned());
    }
    let texts = [
        ("title_de", &raw.title_de),
        ("title_en", &raw.title_en),
        ("cause_de", &raw.cause_de),
        ("cause_en", &raw.cause_en),
        ("consequence_de", &raw.consequence_de),
        ("consequence_en", &raw.consequence_en),
        ("action_de", &raw.action_de),
        ("action_en", &raw.action_en),
    ];
    if let Some((k, _)) = texts.iter().find(|(_, v)| v.trim().is_empty()) {
        return Err(format!("{k} must not be empty"));
    }
    if !raw.title_de.contains("{subject}") || !raw.title_en.contains("{subject}") {
        return Err("titles must name the {subject}".to_owned());
    }
    let threshold = match raw.threshold.as_deref() {
        None => None,
        Some(t) => {
            let d = decimal(t)?;
            if d <= Decimal::ZERO || d > Decimal::ONE {
                return Err(format!("threshold {d} must be in (0, 1]"));
            }
            Some(d)
        }
    };
    let t = |de: &String, en: &String| Texts {
        de: de.clone(),
        en: en.clone(),
    };
    Ok(Value::Alarm(Box::new(AlarmDef {
        priority: raw.priority,
        respond_minutes: raw.respond_minutes,
        on_delay_secs: raw.on_delay_secs,
        off_delay_secs: raw.off_delay_secs,
        threshold,
        title: t(&raw.title_de, &raw.title_en),
        cause: t(&raw.cause_de, &raw.cause_en),
        consequence: t(&raw.consequence_de, &raw.consequence_en),
        action: t(&raw.action_de, &raw.action_en),
    })))
}

fn decimal(s: &str) -> Result<Decimal, String> {
    Decimal::from_str(s).map_err(|_| format!("{s:?} is not a decimal"))
}

fn value(raw: &RawEntry) -> Result<Value, String> {
    // Fields that belong to another value shape are refused, not silently ignored.
    let stray: Vec<&str> = [
        (
            "day_offset",
            raw.day_offset.is_some() && raw.local_time.is_none(),
        ),
        ("max", raw.max.is_some() && raw.min.is_none()),
        ("direction", raw.direction.is_some() && raw.step.is_none()),
        (
            "window_secs",
            raw.window_secs.is_some() && raw.count.is_none(),
        ),
    ]
    .into_iter()
    .filter_map(|(f, bad)| bad.then_some(f))
    .collect();
    if !stray.is_empty() {
        return Err(format!(
            "field(s) {} do not belong to this value",
            stray.join(", ")
        ));
    }
    let shapes = [
        raw.minutes.is_some(),
        raw.local_time.is_some(),
        raw.min.is_some(),
        raw.step.is_some(),
        raw.alarm.is_some(),
        raw.count.is_some(),
        raw.seconds.is_some(),
    ];
    if shapes.iter().filter(|s| **s).count() > 1 {
        return Err(
            "exactly one of minutes, local_time, min/max, step, alarm, count or seconds must be given"
                .to_owned(),
        );
    }
    if let Some(a) = &raw.alarm {
        return alarm(a);
    }
    if let Some(count) = raw.count {
        let window_secs = raw.window_secs.ok_or("a rate needs window_secs")?;
        if count == 0 || window_secs == 0 {
            return Err("count and window_secs must be positive".to_owned());
        }
        return Ok(Value::Rate { count, window_secs });
    }
    if let Some(seconds) = raw.seconds {
        if seconds == 0 {
            return Err("seconds must be positive".to_owned());
        }
        return Ok(Value::Seconds(seconds));
    }
    let time_fmt = time::macros::format_description!("[hour]:[minute]");
    match (&raw.minutes, &raw.local_time, &raw.min, &raw.step) {
        (Some(m), None, None, None) if *m > 0 && 60 % *m == 0 => Ok(Value::Minutes(*m)),
        (Some(m), None, None, None) => Err(format!("minutes {m} must divide 60")),
        (None, Some(t), None, None) => Ok(Value::Gate {
            local_time: Time::parse(t, time_fmt).map_err(|_| format!("{t:?} is not HH:MM"))?,
            day_offset: raw.day_offset.ok_or("a gate needs day_offset")?,
        }),
        (None, None, Some(min), None) => {
            let max = raw.max.as_deref().ok_or("a price range needs max")?;
            let (min, max) = (decimal(min)?, decimal(max)?);
            if min >= max {
                return Err(format!("min {min} must be below max {max}"));
            }
            Ok(Value::PriceRange {
                min: EurPerMwh::new(min),
                max: EurPerMwh::new(max),
            })
        }
        (None, None, None, Some(step)) => {
            let direction = match raw.direction.as_deref() {
                Some("toward-zero") => RoundDirection::TowardZero,
                Some("away-from-zero") => RoundDirection::AwayFromZero,
                Some("nearest-half-even") => RoundDirection::NearestHalfEven,
                other => {
                    return Err(format!(
                        "direction {other:?} must be toward-zero, away-from-zero or nearest-half-even"
                    ));
                }
            };
            Granularity::new(decimal(step)?, direction)
                .map(Value::Step)
                .map_err(|e| e.to_string())
        }
        _ => Err(
            "exactly one of minutes, local_time, min/max, step, alarm, count or seconds must be given"
                .to_owned(),
        ),
    }
}

impl RuleBook {
    /// The bundled source register and packs as `(path, text)`, in a fixed order — for a
    /// fingerprint of the rules a decision was made under.
    pub fn bundled_texts() -> impl Iterator<Item = (&'static str, &'static str)> {
        std::iter::once(("rules/sources.toml", BUNDLED_SOURCES))
            .chain(BUNDLED_PACKS.iter().copied())
    }

    /// The rule packs shipped in `rules/`.
    ///
    /// # Errors
    /// Every problem in the bundled packs (a release never ships with any; the gate checks).
    pub fn bundled() -> Result<Self, Vec<RuleProblem>> {
        Self::parse(BUNDLED_SOURCES, BUNDLED_PACKS)
    }

    /// Parses a source registry and named packs, collecting every problem.
    ///
    /// # Errors
    /// Unknown or incomplete sources, malformed entries, overlapping validity.
    pub fn parse(sources: &str, packs: &[(&str, &str)]) -> Result<Self, Vec<RuleProblem>> {
        let mut problems = Vec::new();
        let mut registry = BTreeMap::new();
        match toml::from_str::<Registry>(sources) {
            Err(e) => problems.push(RuleProblem {
                location: "rules/sources.toml".into(),
                message: e.message().to_owned(),
            }),
            Ok(r) => {
                for s in r.source {
                    let location = format!("rules/sources.toml {}", s.id);
                    for (field, v) in [("title", &s.title), ("publisher", &s.publisher)] {
                        if v.trim().is_empty() {
                            problems.push(RuleProblem {
                                location: location.clone(),
                                message: format!("{field} is empty"),
                            });
                        }
                    }
                    if !s.url.starts_with("https://") {
                        problems.push(RuleProblem {
                            location: location.clone(),
                            message: "url must be https".into(),
                        });
                    }
                    if registry.insert(s.id.clone(), s).is_some() {
                        problems.push(RuleProblem {
                            location,
                            message: "duplicate source id".into(),
                        });
                    }
                }
            }
        }
        let mut entries: BTreeMap<String, Vec<Entry>> = BTreeMap::new();
        for (name, text) in packs {
            let pack = match toml::from_str::<Pack>(text) {
                Ok(p) => p,
                Err(e) => {
                    problems.push(RuleProblem {
                        location: (*name).to_owned(),
                        message: e.message().to_owned(),
                    });
                    continue;
                }
            };
            for raw in pack.rule {
                let location = format!("{name} {}", raw.id);
                if !registry.contains_key(&raw.source) {
                    problems.push(RuleProblem {
                        location: location.clone(),
                        message: format!("cites unregistered source {:?}", raw.source),
                    });
                }
                if raw.valid_until.is_some_and(|u| u <= raw.valid_from) {
                    problems.push(RuleProblem {
                        location: location.clone(),
                        message: "valid_until must be after valid_from".into(),
                    });
                }
                match value(&raw) {
                    Err(message) => problems.push(RuleProblem { location, message }),
                    Ok(value) => entries.entry(raw.id.clone()).or_default().push(Entry {
                        id: raw.id,
                        valid_from: raw.valid_from,
                        valid_until: raw.valid_until,
                        source: raw.source,
                        clause: raw.clause,
                        value,
                        pack: (*name).to_owned(),
                    }),
                }
            }
        }
        for (id, list) in &mut entries {
            list.sort_by_key(|e| e.valid_from);
            for pair in list.windows(2) {
                if pair[0]
                    .valid_until
                    .is_none_or(|until| until > pair[1].valid_from)
                {
                    problems.push(RuleProblem {
                        location: id.to_string(),
                        message: format!(
                            "entries from {} ({}) and {} ({}) overlap",
                            pair[0].valid_from, pair[0].pack, pair[1].valid_from, pair[1].pack
                        ),
                    });
                }
            }
        }
        if problems.is_empty() {
            Ok(Self {
                sources: registry,
                entries,
            })
        } else {
            Err(problems)
        }
    }

    /// Every registered source.
    pub fn sources(&self) -> impl Iterator<Item = &Source> {
        self.sources.values()
    }

    /// The source an entry cites.
    #[must_use]
    pub fn source_of(&self, entry: &Entry) -> Option<&Source> {
        self.sources.get(&entry.source)
    }

    /// Every entry, by rule id.
    pub fn entries(&self) -> impl Iterator<Item = &Entry> {
        self.entries.values().flatten()
    }

    /// The entry of `rule` in force for delivery day `day`.
    ///
    /// # Errors
    /// [`Missing`] if none applies.
    pub fn entry(&self, rule: &str, day: Date) -> Result<&Entry, Missing> {
        self.entries
            .get(rule)
            .and_then(|list| list.iter().find(|e| e.applies(day)))
            .ok_or_else(|| Missing {
                rule: rule.to_owned(),
                day,
            })
    }

    /// The day-ahead market time unit in minutes for `day`.
    ///
    /// # Errors
    /// [`Missing`] if no entry applies or it has the wrong shape.
    pub fn da_mtu(&self, day: Date) -> Result<(u16, &Entry), Missing> {
        let e = self.entry("da.mtu", day)?;
        match e.value {
            Value::Minutes(m) => Ok((m, e)),
            _ => Err(Missing {
                rule: "da.mtu".into(),
                day,
            }),
        }
    }

    /// The instant of gate or publication `rule` for delivery day `day`.
    ///
    /// # Errors
    /// [`Missing`] if no entry applies, it is not a gate, or the instant falls outside the calendar.
    pub fn gate(&self, rule: &str, day: Date) -> Result<(OffsetDateTime, &Entry), Missing> {
        let e = self.entry(rule, day)?;
        let missing = || Missing {
            rule: rule.to_owned(),
            day,
        };
        let Value::Gate {
            local_time,
            day_offset,
        } = e.value
        else {
            return Err(missing());
        };
        let date = day
            .checked_add(time::Duration::days(i64::from(day_offset)))
            .ok_or_else(missing)?;
        let period = flexpool_core::calendar::BusinessDay::new(date).map_err(|_| missing())?;
        // The local wall-clock time on that Berlin day: walk from local midnight. Gates are never in
        // the repeated or skipped hour, so the offset at the gate is the offset of the instant found.
        let target = local_time - Time::MIDNIGHT;
        let mut instant = period.start() + target;
        let local = flexpool_core::calendar::to_berlin(instant).time() - Time::MIDNIGHT;
        if local != target {
            instant += target - local;
        }
        // A local time inside the skipped spring hour does not exist: refuse rather than guess.
        if flexpool_core::calendar::to_berlin(instant).time() != local_time {
            return Err(missing());
        }
        Ok((instant, e))
    }

    /// The harmonised day-ahead price limits for `day`.
    ///
    /// # Errors
    /// [`Missing`] if no entry applies.
    pub fn da_price_limits(&self, day: Date) -> Result<(EurPerMwh, EurPerMwh, &Entry), Missing> {
        let e = self.entry("da.price-limits", day)?;
        match e.value {
            Value::PriceRange { min, max } => Ok((min, max, e)),
            _ => Err(Missing {
                rule: "da.price-limits".into(),
                day,
            }),
        }
    }

    /// The alarm type `rule` in force on `day`.
    ///
    /// # Errors
    /// [`Missing`] if no entry applies or it is not an alarm.
    pub fn alarm(&self, rule: &str, day: Date) -> Result<(&AlarmDef, &Entry), Missing> {
        let e = self.entry(rule, day)?;
        match &e.value {
            Value::Alarm(a) => Ok((a, e)),
            _ => Err(Missing {
                rule: rule.to_owned(),
                day,
            }),
        }
    }

    /// A rate rule (`count` per `window_secs`) in force on `day`.
    ///
    /// # Errors
    /// [`Missing`] if no entry applies or it is not a rate.
    pub fn rate(&self, rule: &str, day: Date) -> Result<(u32, u32, &Entry), Missing> {
        let e = self.entry(rule, day)?;
        match e.value {
            Value::Rate { count, window_secs } => Ok((count, window_secs, e)),
            _ => Err(Missing {
                rule: rule.to_owned(),
                day,
            }),
        }
    }

    /// A duration rule in seconds in force on `day`.
    ///
    /// # Errors
    /// [`Missing`] if no entry applies or it is not a duration.
    pub fn seconds(&self, rule: &str, day: Date) -> Result<(u32, &Entry), Missing> {
        let e = self.entry(rule, day)?;
        match e.value {
            Value::Seconds(s) => Ok((s, e)),
            _ => Err(Missing {
                rule: rule.to_owned(),
                day,
            }),
        }
    }

    /// A granularity rule (`da.volume-granularity`, `da.price-granularity`) for `day`.
    ///
    /// # Errors
    /// [`Missing`] if no entry applies.
    pub fn granularity(&self, rule: &str, day: Date) -> Result<(Granularity, &Entry), Missing> {
        let e = self.entry(rule, day)?;
        match e.value {
            Value::Step(g) => Ok((g, e)),
            _ => Err(Missing {
                rule: rule.to_owned(),
                day,
            }),
        }
    }
}

impl fmt::Display for SourceStatus {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.write_str(match self {
            Self::Checked => "checked",
            Self::Unverified => "unverified",
        })
    }
}