Skip to main content

quilt_zout/
lib.rs

1//! quilt-zout — the Z_out primitive of a Quilt cell.
2
3use serde::{Deserialize, Serialize};
4use std::collections::HashMap;
5
6#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct Zout {
8    pub data: HashMap<String, f64>,
9}
10
11impl Zout {
12    pub fn new() -> Self { Self::default() }
13    pub fn emit(&mut self, k: &str, v: f64) {
14        self.data.insert(k.to_string(), v);
15    }
16    pub fn get(&self, k: &str) -> Option<f64> {
17        self.data.get(k).copied()
18    }
19    pub fn keys(&self) -> impl Iterator<Item = &String> {
20        self.data.keys()
21    }
22}
23
24#[cfg(test)]
25mod tests {
26    use super::*;
27    #[test]
28    fn test_zout_emit() {
29        let mut z = Zout::new();
30        z.emit("result", 42.0);
31        assert_eq!(z.get("result"), Some(42.0));
32    }
33}