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
//! `rudb_strategies()`, the table that says what the engine can be made of.
//!
//! One row per registered implementation of a seam, and one row for every seam that has no
//! implementations yet, which today is twenty six of the twenty seven. A reader who wants to know
//! what rudb will let them swap runs this, and a reader who wants to know what it lets them swap
//! now reads the same table and finds the implementation columns null.
//!
//! The operator is [`Metadata`], which every table of this kind shares. What is here is the list of
//! rows and nothing else.
use rudb_common::{Result, Value};
use rudb_functions::strategy_fields;
use rudb_plan::{Plan, Slice};
use rudb_seam::{SeamId, StrategyRow};
use crate::metadata::{Metadata, text};
use crate::register::registries;
/// Every seam and everything registered against it, in the columns the plan asked for.
///
/// # Errors
///
/// If the plan asks for a column this table does not have.
pub(crate) fn strategies(plan: &Plan, index: u32, columns: Slice) -> Result<Metadata> {
let registered = registries().rows();
let mut rows = Vec::new();
for seam in SeamId::ALL.iter().copied() {
let mut any = false;
for row in registered.iter().filter(|row| row.seam == seam) {
rows.push(implemented(row));
any = true;
}
if !any {
rows.push(planned(seam));
}
}
Metadata::new("rudb_strategies", &strategy_fields(), &rows, plan, index, columns)
}
/// The row an implementation produces.
fn implemented(row: &StrategyRow) -> Vec<Value> {
vec![
text(row.seam.name()),
text(row.seam.milestone()),
text(row.seam.describe()),
text(row.name),
text(row.describe),
text(&row.provenance.to_string()),
text(&row.determinism.to_string()),
Value::Boolean(row.is_reference),
Value::Boolean(row.is_default),
]
}
/// The row a seam with no registry produces.
///
/// The three columns that describe the seam are filled and the six that describe an implementation
/// are null, rather than the seam being left out of the table. A seam nobody has built is a
/// commitment somebody has made, the milestone column says who owes it, and a table that listed
/// only what exists would make the engine look finished.
fn planned(seam: SeamId) -> Vec<Value> {
vec![
text(seam.name()),
text(seam.milestone()),
text(seam.describe()),
Value::Null,
Value::Null,
Value::Null,
Value::Null,
Value::Null,
Value::Null,
]
}