Skip to main content

PersistedPolicy

Struct PersistedPolicy 

Source
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: u64

The 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: bool

Operator intent, independent of state.

§state: PolicyState§cache_policy: CachePolicy§workspace_kind: WorkspaceKind

ephemeral 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: u64

Optimistic-concurrency token. Not an identifier of anything.

Trait Implementations§

Source§

impl Clone for PersistedPolicy

Source§

fn clone(&self) -> PersistedPolicy

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PersistedPolicy

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for PersistedPolicy

Source§

impl PartialEq for PersistedPolicy

Source§

fn eq(&self, other: &PersistedPolicy) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for PersistedPolicy

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more