Skip to main content

InteractionDefinition

Struct InteractionDefinition 

Source
pub struct InteractionDefinition {
    pub schema: DefinitionTag,
    pub kind: InteractionKind,
    pub revision: Revision,
    pub markdown: String,
    pub controls: Vec<Control>,
    pub features: Vec<FeatureDemand>,
    pub note: Option<String>,
}
Expand description

The immutable semantic model of one interaction.

Identity is a DefinitionId — a ContentId over the canonical encoding of this whole record, which is also its exact form digest.

Fields§

§schema: DefinitionTag

Versioned type tag; see DEFINITION_SCHEMA_V1.

§kind: InteractionKind

What kind of interaction this is.

§revision: Revision

Which revision of this definition’s authoring lineage this is.

§markdown: String

The readable body — canonical Markdown, the fallback every surface can render (ADR law 1). Held as text; parsing belongs to newt_core::markup, not to the protocol layer.

§controls: Vec<Control>

The controls, in presentation order.

§features: Vec<FeatureDemand>

What a surface must be able to do to present this faithfully, each demand marked required or optional.

§note: Option<String>

A subordinate line beneath the body — a control hint, a danger warning. Readable content like markdown, kept separate because surfaces place it differently and the legacy prompt already distinguishes the two.

Omitted when absent, so a definition without one is byte-identical to one written before this field existed.

Implementations§

Source§

impl InteractionDefinition

Source

pub fn is_decision_shaped(&self) -> bool

Whether this definition can ONLY be a binary decision: one ControlKind::Choice control offering exactly two options, one granting and the other refusing or backing out.

Keys on SemanticRole, never on the option count. Allow + Deny is a decision, Allow + Cancel is a decision that offers a way out, and Value + Value is a two-way pick and not a decision at all.

Deliberately narrower than “is a yes/no”, and the gap is the point. A lone ControlKind::Toggle is also a yes/no — and it is the case that settles #1912, because InteractionKind::Choice means “pick one of a fixed, DISPLAYED set” and a toggle displays no set, so Choice cannot describe it and Confirm is not redundant with it.

But a lone toggle is ALSO a one-field form — “remember this? [ ]” — and nothing in the shape says which. So the toggle case is admitted by InteractionKind::Confirm and never required of it. This predicate reports only what a shape can prove, which is why the guard in InteractionDefinition::new enforces one direction and not both.

Source

pub fn new( kind: InteractionKind, markdown: impl Into<String>, controls: Vec<Control>, ) -> Self

Build a definition carrying the current schema tag.

Source

pub fn definition_id(&self) -> Result<DefinitionId, ProtocolError>

This definition’s identity, which is also its exact form digest.

§Errors

Propagates a canonical-encoding failure.

Source

pub fn schema_tag(&self) -> &'static str

The schema tag, as a string.

Reading it needs no check: the tag is a TYPE that deserializes from exactly one value, so a record of this type cannot carry any other one. What used to be a runtime ensure_known_schema is now a thing the wire cannot express — and the published schema says so with a const, so a foreign implementor validating against the wrong record’s schema fails instead of passing.

Trait Implementations§

Source§

impl Clone for InteractionDefinition

Source§

fn clone(&self) -> Self

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 ContentAddressable for InteractionDefinition

Source§

fn canonical_form(&self) -> Result<Vec<u8>, ContentError>

Produce the deterministic byte representation of this value. Read more
Source§

fn content_id(&self) -> Result<ContentId, ContentError>

Compute this value’s ContentId. Read more
Source§

fn verify(&self, expected: &ContentId) -> Result<bool, ContentError>

Check whether this value’s content id matches an expected id. Read more
Source§

fn ensure_content_id(&self, expected: &ContentId) -> Result<(), ContentError>

Verify, returning an error on mismatch instead of Ok(false). Read more
Source§

fn from_canonical_form(bytes: &[u8]) -> Result<Self, ContentError>
where Self: Sized + DeserializeOwned,

Checked ingress: decode a value from its canonical form, proving the bytes reproduce it — a checked partial inverse of canonical_form. Read more
Source§

impl Debug for InteractionDefinition

Source§

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

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

impl<'de> Deserialize<'de> for InteractionDefinition

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for InteractionDefinition

Source§

impl PartialEq for InteractionDefinition

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl Serialize for InteractionDefinition

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for InteractionDefinition

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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.