// GENERATED by gsap/emit_rust.js -- shared types of the golden fixture modules. #![allow(dead_code)] /// One flattened value of an irregular golden record ("extra", "meta", snapshots). #[derive(Clone, Copy, Debug, PartialEq)] pub enum Val { F(f64), B(bool), S(&'static str), Null, } /// Flattened record: dotted keys ("immediate_after_create.x", "callbacks.0"); arrays also carry ".len". pub type Pairs = &'static [(&'static str, Val)]; /// One column of a columnar sample table, aligned with the case's `t`. #[derive(Clone, Copy, Debug)] pub struct Series { pub name: &'static str, pub v: &'static [f64], } pub fn val(p: &[(&'static str, Val)], key: &str) -> Option { p.iter().find(|(k, _)| *k == key).map(|(_, v)| *v) } pub fn num(p: &[(&'static str, Val)], key: &str) -> f64 { match val(p, key) { Some(Val::F(x)) => x, other => panic!("golden key {key}: expected a number, got {other:?}"), } } pub fn flag(p: &[(&'static str, Val)], key: &str) -> bool { match val(p, key) { Some(Val::B(b)) => b, other => panic!("golden key {key}: expected a bool, got {other:?}"), } } pub fn text(p: &[(&'static str, Val)], key: &str) -> Option<&'static str> { match val(p, key) { Some(Val::S(s)) => Some(s), Some(Val::Null) | None => None, other => panic!("golden key {key}: expected a string, got {other:?}"), } } /// The strings stored under ".0", ".1", ... (".len" entries). pub fn list(p: &[(&'static str, Val)], key: &str) -> Vec<&'static str> { let n = num(p, &format!("{key}.len")) as usize; (0..n) .map(|i| text(p, &format!("{key}.{i}")).unwrap_or("")) .collect() } pub fn column(s: &[Series], name: &str) -> &'static [f64] { s.iter() .find(|c| c.name == name) .map(|c| c.v) .unwrap_or_else(|| panic!("golden series {name} missing")) }