Skip to main content

mur_common/
expression.rs

1//! Shared expression-change type used by both Hub and sidecar runtimes.
2//!
3//! The richer types (DwellSpec, ExpressionTrigger) live in `hub::trigger`
4//! because they require YAML parsing. This module holds only the wire-safe
5//! output type that the sidecar pushes to Hub over IPC.
6
7use serde::{Deserialize, Serialize};
8
9/// Describes the expression the pet should display, as emitted by the
10/// ExpressionStateMachine.  Travels from mur-agent-runtime → Hub via IPC.
11#[derive(Debug, Clone, Serialize, Deserialize)]
12pub struct ExpressionChange {
13    /// Name of the expression (e.g. `"idle"`, `"smile"`, `"error"`).
14    pub expression: String,
15    /// Text to show in the speech bubble, if any.
16    pub bubble_text: Option<String>,
17}
18
19#[cfg(test)]
20mod tests {
21    use super::*;
22
23    #[test]
24    fn expression_change_roundtrip() {
25        let ec = ExpressionChange {
26            expression: "smile".into(),
27            bubble_text: Some("Hello!".into()),
28        };
29        let json = serde_json::to_string(&ec).unwrap();
30        let back: ExpressionChange = serde_json::from_str(&json).unwrap();
31        assert_eq!(back.expression, "smile");
32        assert_eq!(back.bubble_text.as_deref(), Some("Hello!"));
33    }
34}