Skip to main content

cufflink_types/host/
wait.rs

1//! How a host call waits: holding the guest's execution slots, or giving
2//! them back until its answer arrives.
3
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
7#[serde(rename_all = "snake_case")]
8pub enum Wait {
9    #[default]
10    Hold,
11    Release,
12}
13
14impl Wait {
15    pub fn is_hold(&self) -> bool {
16        matches!(self, Wait::Hold)
17    }
18}
19
20#[cfg(test)]
21mod tests {
22    use super::Wait;
23    use crate::host::tests::{refused, round_trip};
24    use serde_json::json;
25
26    #[test]
27    fn a_wait_is_hold_unless_it_says_release() {
28        round_trip(&Wait::Hold, json!("hold"));
29        round_trip(&Wait::Release, json!("release"));
30        refused::<Wait>(json!("park"));
31        assert!(Wait::default().is_hold());
32        assert!(!Wait::Release.is_hold());
33    }
34}