Skip to main content

euv_core/dynamic/contract/
trait.rs

1use super::*;
2
3/// Compile-time strongly-typed dynamic component interface shared by Wasm Component (WIT) and Declarative Data channels.
4pub trait DynamicComponentContract: 'static {
5    /// Strongly-typed input properties validated by the Rust compiler at every call site.
6    type Props: Serialize + for<'de> Deserialize<'de> + Clone + PartialEq + 'static;
7
8    /// Strongly-typed output events validated by the Rust compiler on every handler.
9    type Event: Serialize + for<'de> Deserialize<'de> + Clone + 'static;
10
11    /// Canonical interface identifier verified against pinned release artifacts before activation.
12    const INTERFACE_ID: &'static str;
13
14    /// Interface contract version independent of implementation and state schema versions.
15    const INTERFACE_VERSION: u32;
16
17    /// Expected component local state schema version.
18    const STATE_SCHEMA_VERSION: u32;
19
20    /// Returns the WIT interface source defining this component contract.
21    ///
22    /// # Returns
23    ///
24    /// - `&'static str` - Canonical WIT definition.
25    fn wit_definition() -> &'static str;
26
27    /// Builds the compiled native fallback UI tree used before any remote release is active.
28    ///
29    /// # Arguments
30    ///
31    /// - `&Self::Props` - Strongly-typed component properties.
32    ///
33    /// # Returns
34    ///
35    /// - `DynamicNodeSpec` - Fallback declarative UI subtree.
36    fn fallback_spec(props: &Self::Props) -> DynamicNodeSpec;
37
38    /// Decodes a dynamic UI control action back into a strongly-typed `Self::Event`.
39    ///
40    /// # Arguments
41    ///
42    /// - `&DynamicActionEvent` - Raw interaction event from a dynamic slot control.
43    /// - `&Self::Props` - Active typed properties of the slot.
44    ///
45    /// # Returns
46    ///
47    /// - `Option<Self::Event>` - Typed event when recognized by this contract.
48    fn decode_action(action: &DynamicActionEvent, props: &Self::Props) -> Option<Self::Event>;
49}