#[non_exhaustive]pub struct Consequence {
pub when: Option<Value>,
pub severity: Severity,
pub message: String,
}Expand description
A cost of changing a field, declared on the rule that governs it.
A different fact from Presentation’s
Tint. A tint says how loudly to draw a field; a consequence
says what happens if the user goes through with the change — that switching
a metadata format rewrites every document in the archive, that turning a
recycle bin off makes deletion unrecoverable. A field can be drawn calmly
and still be expensive to change, and a field can be drawn in red and cost
nothing.
Three properties are deliberate, and a host that assumes otherwise will be subtly wrong:
- A guard names the value being landed, not a transition. There is no
from/to matrix:
Consequence::whennames a destination. The host knows the current value; this crate does not. A cost that only applies coming from a particular value is declared as a plain consequence on the destination, and suppressed by the host that can see the difference. - Deletion resolves to whatever the host’s default is. This crate has no
concept of a field being absent, and
Value::Nullis not a spelling for it — a written null is a real value, whichFieldType::Nullcoerces. A host removing a field should ask about the value the removal actually resolves to, or about nothing. - No-op detection is the caller’s.
FieldRule::consequences_ofhas no current value to compare against, so re-setting a field to what it already holds answers exactly as setting it afresh does. Suppressing that is the host’s job — and it is what makes the first property work.
#[non_exhaustive]: built from Consequence::always or
Consequence::when plus Consequence::severity. Reading the fields is
unchanged.
use fig::Value;
use fig_schema::{Consequence, Severity};
let c = Consequence::when(false, "Deleted items will be gone for good.")
.severity(Severity::ConfirmExplicitly);
assert_eq!(c.when, Some(Value::Bool(false)));Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.when: Option<Value>The destination value this applies to, or None for any change to the
field. Compared with Value::eq_canonical, so a guard written
Value::Int(1) still matches a document that parsed 1 as a
Value::Uint.
severity: SeverityWhat the host should do about it.
message: StringThe sentence to show. Prose rather than a taxonomy: a consequence is specific to the field, and no closed set of effect kinds would spare the author from writing it.
Implementations§
Source§impl Consequence
impl Consequence
Sourcepub fn always(message: impl Into<String>) -> Self
pub fn always(message: impl Into<String>) -> Self
A consequence of changing the field at all, whatever the new value.
Severity::Notice until Consequence::severity says otherwise.
Sourcepub fn when(value: impl Into<Value>, message: impl Into<String>) -> Self
pub fn when(value: impl Into<Value>, message: impl Into<String>) -> Self
A consequence of changing the field to value — a destination, not a
transition. See Consequence for why there is no from/to matrix.
Sourcepub fn applies_to(&self, value: &Value) -> bool
pub fn applies_to(&self, value: &Value) -> bool
Whether this applies to landing value. An unguarded consequence
applies to every value.
Trait Implementations§
Source§impl Clone for Consequence
impl Clone for Consequence
Source§fn clone(&self) -> Consequence
fn clone(&self) -> Consequence
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more