pub struct PersistedPolicy {Show 14 fields
pub id: PolicyId,
pub target: ScaleTarget,
pub installation_id: u64,
pub host_id: HostId,
pub requested_host_label: HostLabel,
pub routing_labels: Option<RoutingLabels>,
pub min_capacity: u16,
pub max_capacity: Option<NonZeroU16>,
pub enabled: bool,
pub state: PolicyState,
pub cache_policy: CachePolicy,
pub workspace_kind: WorkspaceKind,
pub workspace_root: Option<LocalAbsolutePath>,
pub revision: u64,
}Expand description
Every stored column of one policy, named rather than positional.
Why this is a struct. ScalePolicy::from_persisted took eleven
positional arguments under #[allow(clippy::too_many_arguments)], and two of
them — installation_id and revision — are both bare u64. Transposing
them type-checked and compiled: the policy would then have authenticated
against an installation id of 0 or 1 while presenting its installation id
as an optimistic-concurrency token, so every write would have raced and every
GitHub call would have failed to authenticate, with nothing in either
signature to catch it.
b2 maps database columns onto this type. With a struct that mapping is
checked by name at compile time; positionally it was checked by nothing.
That guarantee covers the Rust side of the mapping and no more. It is the
field names that the compiler checks, not the column names they are read
from: PersistedPolicy { installation_id: row.get("revision")?, … } compiles
exactly as happily as the correct version, and reintroduces the very
transposition described above. b2 still owes a test that loads a row whose
columns hold distinguishable values and asserts each landed in the field of
the same name; this type does not supply one.
Construct it with a struct literal so every field is written down at the call
site — that is the whole point, and a builder or a Default would give the
omission back.
Fields§
§id: PolicyId§target: ScaleTarget§installation_id: u64The GitHub App installation this policy authenticates through.
host_id: HostId§requested_host_label: HostLabel§routing_labels: Option<RoutingLabels>Some for an Autoscale policy, None for a MonitorOnly one (D19).
min_capacity: u16§max_capacity: Option<NonZeroU16>§enabled: boolOperator intent, independent of state.
state: PolicyState§cache_policy: CachePolicy§workspace_kind: WorkspaceKindephemeral or persistent, stored beside the root below (D4). The two
are separate columns rather than one because that is what SQLite holds;
WorkspacePolicy::from_persisted is what refuses the combinations this
crate cannot have written.
workspace_root: Option<LocalAbsolutePath>The configured persistent root: Some exactly when workspace_kind is
persistent.
revision: u64Optimistic-concurrency token. Not an identifier of anything.
Trait Implementations§
Source§impl Clone for PersistedPolicy
impl Clone for PersistedPolicy
Source§fn clone(&self) -> PersistedPolicy
fn clone(&self) -> PersistedPolicy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more